erikbeam Posted May 21, 2008 Share Posted May 21, 2008 My goal is to send an email link to customers that includes their gallery number in the URL, so the website knows which information they get to see after they create an account. Ex: Click here to view your gallery: www.xyz.com/form.php?gallery=123456 I've got /form.php setup to get username and password and send them to a dynamic page that will display their images based on the initial gallery number: <form action="insert.php?gallery=<?php echo $gallery;?>" method="post"> Username: <input type="text" name="username" /> Password: <input type="password" name="password" /> Then in "/insert.php" I want to post the username, password, and gallery number to the MySQL database: $sql="INSERT INTO customer (username, password, gallery) VALUES ('$_POST[username]','$_POST[password]','$_POST[gallery]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } The username and password both post to the database, but the gallery value is blank. The "?gallery=123456" part passes to /insert.php just fine, and to double check that the gallery value is passed I put in an: echo "Welcome to gallery " . $gallery . ", " . $username ."."; The gallery number shows up fine here. I've tried declaring "gallery" in the MySQL table as both VARCHAR and INT. VARCHAR will leave a blank value and INT leaves a value of 0. Any idea where I went wrong? Link to comment https://forums.phpfreaks.com/topic/106565-solved-1st-day-of-phpmysql-im-missing-something-here/ Share on other sites More sharing options...
rhyboo Posted May 21, 2008 Share Posted May 21, 2008 Hey there, Try this $sql="INSERT INTO customer (username, password, gallery) VALUES ('".$_POST["username"]"'."'$_POST["password"]'".'"$_POST["gallery"].'")"; if (!mysql_query($sql,$con)) //Do you have a varaible $con in your script somewhere's that actually performs a function (db connection, etc) { die('Error: ' . mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/106565-solved-1st-day-of-phpmysql-im-missing-something-here/#findComment-546263 Share on other sites More sharing options...
erikbeam Posted May 21, 2008 Author Share Posted May 21, 2008 I got this message: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/erikmcom/public_html/dbtest/insert.php on line 15 Link to comment https://forums.phpfreaks.com/topic/106565-solved-1st-day-of-phpmysql-im-missing-something-here/#findComment-546265 Share on other sites More sharing options...
jamesnes Posted May 21, 2008 Share Posted May 21, 2008 The problem you have lies in where you are trying to get the value of gallery from. Try the following: $sql="INSERT INTO customer (username, password, gallery) VALUES ('$_POST[username]','$_POST[password]',$_GET[gallery])"; The reason for this is because although you are using the post method for the form, the url submitted is where you are passing the gallery variable, and as such it will be in the $_GET array, not the $_POST array. Link to comment https://forums.phpfreaks.com/topic/106565-solved-1st-day-of-phpmysql-im-missing-something-here/#findComment-546266 Share on other sites More sharing options...
erikbeam Posted May 21, 2008 Author Share Posted May 21, 2008 Perfect. That makes a lot of sense to me now. Thank you very much. Link to comment https://forums.phpfreaks.com/topic/106565-solved-1st-day-of-phpmysql-im-missing-something-here/#findComment-546267 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.