Jump to content

Recommended Posts

Hi guys

 

Im looking to save the contents of 4 textboxes to a mySql db. Using wamp, phpmyadmin etc.

 

?php
$Name = $_Post('Name');
$Age = $_Post('Age');
$Sex = $_Post('Sex');
$Address_1 = $_Post('Address_1');

mysql_connect("127.0.0.1","user","") or die ('Error: ' .mysql_error());
mysql_select_db("user");

$query ="INSERT INTO users(Name,Age,Sex,Address_1) VALUES('".$Name."', '".$Age."','".$Sex."','".$Address_1."');

mysql_query($query) or die ('Error updating datadase');
mysql_Close();

?>

This is the code im using, it dosent seem to do anything to the database..... can someone point out where im going wrong... thanks

Post using the code tags

 

<?php
$Name = $_POST['Name'];
$Age = $_POST['Age'];
$Sex = $_POST['Sex'];
$Address_1 = $_POST['Address_1'];

mysql_connect("127.0.0.1","user","password") or die ('Error: ' .mysql_error());
mysql_select_db("user");
$query ="INSERT INTO users(Name,Age,Sex,Address_1) VALUES('$Name', $Age','$Sex','$Address_1')";
mysql_query($query) or die ('Error updating datadase');
mysql_close();
?>

 

Missed the POST and also the square brackets, must be a little tired

Should the POST values be uppercased?

Did you look in your error log?  Your code has several obvious syntax errors.

 

The syntax for accessing arrays is to use [] not ().  Also $_POST is the name of the superglobal array... all caps.

 

$Name = $_POST['Name'];

 

Also, php supports interpolation when you use double quotes.  The values of variables will be inserted into the string, so your code will be alot easier to read if you utilize it rather than concatenation.

 

$query ="INSERT INTO users (Name,  Age, Sex, Address_1) VALUES ('$Name', '$Age', '$Sex', '$Address_1')";

 

What database type is the Age column?  If it's not a string you would not include the single quotes around it in the values section of the query.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.