Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Php Form - Not inserting into DB

Status
Not open for further replies.

WizyWyg

Technical User
Jan 31, 2001
854
JP
After figuring out my previous problem with help, now, one of my other forms is not working. The following code:

Code:
<html>

<?php
$db = mysql_pconnect(&quot;localhost&quot;, &quot;root&quot;);
@mysql_select_db(&quot;accessories&quot;,$db) or die(mysql_error());

if ($submit) {
  // process form
  $sql = &quot;INSERT INTO user (name) VALUES ('$name')&quot;;
  $result = mysql_query($sql) or die(mysql_error().$sql);

  echo &quot;Thank you! Information entered. Click <a href=admin.php>here</a> to go back.\n&quot;;
}
else{
  // display form
?>
<form method=&quot;post&quot; action=&quot;<?php echo $PHP_SELF; ?>&quot;>
  <table width=40%>
    <tr>
      <td>Name</td>
      <td><input type=&quot;Text&quot; name=&quot;name&quot; size=&quot;25&quot; maxlength=&quot;50&quot;></td>
      </tr>
  </table>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Enter User&quot;>
  </form>
<?php
} // end if
?>
</body>
</html>

is inserting &quot;blank&quot; data (where it should be a name) into my database under table user column name.


It was working before, but now its not working. All I get is a blank where the new user's name should be.
 
Oops nevermind, got it figured out ^_^
 
Be weary of left joins. The workings of left joins are that they do a row-by-row search for matches based on your query (ON and USING()), and if something does not match on the left table, a resulting row is still returned (a 'fake' row) and NULLS are put in place to accommodate. Also, there is greater overhead when using left joins.

I placed a sample on a dev box of mine using the straight join I provided in my prior posting (SELECT user.name,accessory.* FROM user,accessory WHERE user.userId=accessory.userId).


and you can do inserts here


I ran tests using
'SELECT user.name,accessory.* FROM user,accessory WHERE user.userId=accessory.userId'

and your left join
'select accessory.accessId ,accessory.item,accessory.snumber,accessory.userId, user.userId, user.name from accessory left join user on accessory.userId = user.userId'
and correct information is returned for both, but we get extraneous columns in yours (userId) which is not necessary, and there is an extra (approximate) .5 seconds longer delay.

Check it out and let me know what you think.

Chad. ICQ: 54380631
 
Its
myql_connect(&quot;localhost&quot;,&quot;root&quot;) aint it ?
 
For what i see your problem could be with the var.

Have you tried to replace $name in the INSERT by $HTTP_POST_VARS[name]? or by $HTTP_GET_VARS[name] if the form has a get method?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top