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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with mysql...

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm having a hard time using the insert command:

Code:
function do_entry($entry_name, $entry_email, $entry_url, $entry_msn, $entry_aim, $entry_icq, $entry_yahoo, $entry_message) {

global $admin, $sitename, $cookie, $prefix;

mysql_connect('localhost', 'username', 'pass') or die ('Cannot connect to database!');

mysql_select_db ('db') or die ('Cannot select database!');

$query="INSERT INTO guestbook (id, name, email, url, msn, aim, icq, yahoo, message, data, time) VALUES (6, '$entry_name', '$entry_email', '$entry_url', '$entry_msn', '$entry_aim', '$entry_icq', '$entry_yahoo', '$entry_message', 'date', 'time')";
mysql_query($query);

echo "entry added!";

}

What am I doing wrong?
 
Are you sure that you waat to pass in a value for id? It's best to make it an auto-increment and just leave out the (id) VALUES (6) part. If you have id set to auto-increment already, and if an entry exists for id=6, then you will get an error.

Rick If I have helped you just click the first link below to let me know :)
 
Thanks, but it still doesn't work. I'm not getting any errors. The only problem is the script doesn't insert a row into the table.
 
I changed my code a bit:

Code:
function do_entry($entry_name, $entry_email, $entry_url, $entry_msn, $entry_aim, $entry_icq, $entry_yahoo, $entry_message) {

global $admin, $sitename, $cookie, $prefix, $dbi;

$result = sql_query("INSERT INTO guestbook VALUES (, '$entry_name', '$entry_email', '$entry_url', '$entry_msn', '$entry_aim', '$entry_icq', '$entry_yahoo', '$entry_message', 'date', 'time')", $dbi);

// Convert smilies
$entry_message = do_smilies($smilie);

Header("Location: modules.php?name=Guestbook");

}

Still doesn't do the insert commands. :p lol
 
of course ... after the ( you have a comma.

if the first field of the table is an auto_increment, just skip it in the values set.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Thanks for all the replies. I fixed it:

Code:
function do_entry($entry_name, $entry_email, $entry_url, $entry_msn, $entry_aim, $entry_icq, $entry_yahoo, $entry_message) {

global $admin, $sitename, $cookie, $prefix, $dbi;

$dateandtime = "test";

$result = sql_query("INSERT INTO ".$prefix."_guestbook VALUES ('', '$entry_name', '$entry_email', '$entry_url', '$entry_msn', '$entry_aim', '$entry_icq', '$entry_yahoo', '$entry_message', 'datetime')", $dbi);

$result = sql_query($query = "UPDATE ".$prefix."_guestbook SET name='".$entry_name."', email='".$entry_email."', url='".$entry_url."', msn='".$entry_msn."', aim='".$entry_aim."', icq='".$entry_icq."', yahoo='".$entry_yahoo."', message='".$entry_message."', datetime='".$dateandtime."' WHERE id='".$entry_id."')", $dbi);

// Convert smilies
$entry_message = do_smilies($smilie);

Header("Location: modules.php?name=Guestbook");

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top