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
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') ");

 

Link to comment
Share on other sites

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 '

Link to comment
Share on other sites

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.