confused and dazed Posted December 21, 2011 Share Posted December 21, 2011 Hello internet. I am trying to set up a query that will check to see if there is a row in the database that has the same name the user is trying to submit. Here is my code... how do I make this work? <?php$con = mysql_connect("xxx","xxx","xxx");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("xxx", $con);$entry=mysql_query("Select FROM testmysql where name='$_POST[rname]'");if($entry='$_POST[rname]');{echo "There is an entry that already exists with the name you selected. Please change the name and re-submit. Thanks.";die(); Link to comment Share on other sites More sharing options...
thescientist Posted December 21, 2011 Share Posted December 21, 2011 $entry is only going to be a mysql_resourcehttp://php.net/manua...mysql-query.php you need to check if any matches were found. simple as checking the number of rows returned for instance.http://php.net/manua...ql-num-rows.php edit: also, you are using an assignment operator, terminating the if statement before the curly brace, and the curly braces don't match. At the very least you have error reporting turned on while you are developing. if($entry='$_POST[rname]');{ Link to comment Share on other sites More sharing options...
confused and dazed Posted December 21, 2011 Author Share Posted December 21, 2011 O.K. so here is an update but I cant get it to work<?php$con = mysql_connect("xxx","xxx","xxx");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("xxx", $con);$result=mysql_query("Select FROM testmysql where name='$_POST[name]'");$num_rows = mysql_num_rows($result);if($num_rows != 0);{echo "There is an entry that already exists with the name you selected. Please change the name on your and re-submit. Thanks.";die();} Link to comment Share on other sites More sharing options...
thescientist Posted December 21, 2011 Share Posted December 21, 2011 you haven't told your query what column(s) to SELECT onhttp://www.w3schools.com/sql/sql_select.asp Link to comment Share on other sites More sharing options...
confused and dazed Posted December 21, 2011 Author Share Posted December 21, 2011 I got it to work...What I was not getting was that $num_rows = mysql_num_rows($result); returned a number NOT the name that was entered by the user.... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.