Re: question about php and sql
Posted: Sat May 07, 2011 3:09 pm
I'm just happy I got it rightjacek wrote:The above method is correct, although it would be better to use the mysql COUNT() function.



I'm just happy I got it rightjacek wrote:The above method is correct, although it would be better to use the mysql COUNT() function.
<?php $connect = mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("ta2shop") or die(mysql_error()); // form data $postal = $_POST['postal']; $random = 'TA2_'.rand(0123456789,9876543210); $date = date("Y-m-d"); if (isset($_POST['generate'])) { if($_POST['postal']) { $check = mysql_query("SELECT postal_code FROM postal_codes WHERE '$postal'=postal"); $numrows = mysql_num_rows($check); if ($numrows!=1) echo"Postal code has already been used"; else { $query = mysql_query("INSERT INTO postal_codes VALUES('','$postal','$random','$date')") or die(mysql_error()); echo "<center>Success, your tracker ID is:".$random."</center>"; } } else echo "<center>You must provide a postal code!</center>"; } ?>but now sql prints this:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\trabajos\ta2shop - tienda\administracion\postal-code\index.php on line 46
WHERE '$postal'=postalThis doesn’t look right to me
WHERE `postal` = '$postal_code'Unsure on the column names though
The other way round works on my scriptsjacek wrote:I was thinking more of
WHERE `postal` = '$postal_code'Unsure on the column names though
WHERE 'postal_code' = '$postal'If you look at the query in the above post by him that looks right.