Jump to content

[SOLVED] Inserting dat into table


dink87522

Recommended Posts

I have

$servername = "localhost";
$username = "admin_admin";
$password = "admin";
$dbCon = mysql_connect($servername, $username, $password);
   if (!$dbCon)
  {
  die();
  }
$userID = "a";
$score = 33;
$ageGroup = "mm";
$dateTimeStamp = "2345432";
mysql_select_db("admin_GTWE") or die(mysql_error());
mysql_query("INSERT INTO 'Highscores' (userID, score, ageGroup, saveTimeDate) VALUES($userID, $score, $ageGroup, $dateTimeStamp) ");

 

except it doesn't work (althoguh nor does it throw any errors). The database details are defiantly correct and I can connect to it. The table exists. The rows exist.

 

However I do have another column first called ID which is the priamry key?

Link to comment
https://forums.phpfreaks.com/topic/171468-solved-inserting-dat-into-table/
Share on other sites

Hey,

 

instead of

mysql_query("INSERT INTO 'Highscores' (userID, score, ageGroup, saveTimeDate) VALUES($userID, $score, $ageGroup, $dateTimeStamp) ");

 

Try:

mysql_query("INSERT INTO 'Highscores' (userID, score, ageGroup, saveTimeDate) VALUES ('$userID', '$score', '$ageGroup', '$dateTimeStamp') ");

 

You have no error handling. Also, You left in your database passwords so I took them out... Do the same for your post or you could get hackers!

 

Try this:

 

$servername = "localhost";
$username = "xxxx";
$password = "xxxx";
$dbCon = mysql_connect($servername, $username, $password);
   if (!$dbCon)
     {
     die();
     }
$userID = "a";
$score = 33;
$ageGroup = "mm";
$dateTimeStamp = "2345432";
mysql_select_db("admin_GTWE") or die(mysql_error());
mysql_query("INSERT INTO `Highscores` (userID, score, ageGroup, saveTimeDate) VALUES('$userID', '$score', '$ageGroup', '$dateTimeStamp') ") or die("There was an error. Error returned was: ".mysql_error());

 

Also on Highscores I used ` not '

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.