IamMeCone Posted May 15, 2007 Share Posted May 15, 2007 I made this script where it connects to a database (name deifned in config.php) and adds a row to a table (name defined in config.php) and adds a username in column 1 a password in column 2 an email address in column 3 and slkey (dont worry about this its just a string) in V 4 the number 0 in column 5 and the text "cart is empty" in column 6. Well there is something wrong cause column 6 is always blank i dont know why. There is a snapshot at iammecone.com/login/untitled.bmp that shows the blank column and all the tests i ran <?php include("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); // check if the username is taken $check = "select id from $table where username = '".$_POST['username']."';"; $qry = mysql_query($check) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows != 0) { echo "Sorry, there the username $username is already taken.<br>"; echo "<a href=register.html>Try again</a>"; exit; } else { // insert the data $insert = mysql_query("INSERT INTO $table (username, password, email, slkey, owe, cart) VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '".$_POST['slkey']."', '".$_POST[0]."', '".$_POST["cart is empty"]."')") or die("Could not insert data because ".mysql_error()); // print a success message echo "Your user account has been created!<br>"; echo "Now you can <a href=login.html>log in</a>"; } ?> Link to comment https://forums.phpfreaks.com/topic/51564-php-script-doesnt-fill-in-last-column/ Share on other sites More sharing options...
Garath531 Posted May 15, 2007 Share Posted May 15, 2007 I think this problem occurs because the $_POST variable is used to pass values from a form. If you are just trying to fill in the value your cart is empty, you would just put that between single quotes. Change $insert = mysql_query("INSERT INTO $table (username, password, email, slkey, owe, cart) VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '".$_POST['slkey']."', '".$_POST[0]."', '".$_POST["cart is empty"]."')") or die("Could not insert data because ".mysql_error()); to this. $insert = mysql_query("INSERT INTO $table (username, password, email, slkey, owe, cart) VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '".$_POST['slkey']."', '0', 'Cart is Empty')") or die("Could not insert data because ".mysql_error()); (I'm assuming that for owe you are trying to enter the value of "0") See if that works for you. Garath531 **EDIT**Accidentally added quote tags. Link to comment https://forums.phpfreaks.com/topic/51564-php-script-doesnt-fill-in-last-column/#findComment-253954 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.