apalecka 04-02-2007, 02:20 PM Hello
I've set up this table of customers details and I'm trying to retrieve particular
customer details with the following code.
I keep getting the following error messsage and I'm not sure what it means?
Warning: 0 is not a MySQL result index in <file name...> on line 7.
If anywone could give me some advice on what I should, I'd be very gratefull!
Thanks!
Michael
<?php
$customer_no = $_POST[$customer_no];
$mysql_link = mysql_connect ("unix.lsbu.ac.uk", "paleckaa", "butteph9");
$testresult = mysql_select_db ("paleckaa", $mysql_link);
$query="SELECT * FROM customers WHERE customer_no=$customer_no";
$query_result = mysql_query ($query, $mysql_link);
if ( mysql_num_rows ($query_result)>0) {
print "<table border=\"1\" width=\"100%\">";
while ($row = mysql_fetch_row ($query_result)) {
print "<td width=\"10%\">$row[customer_no]</td>";
print "<td width=\"30%\">$row[first_name]</td>";
print "<td width=\"30%\">$row[last_name]</td>";
print "<td width=\"30%\">$row[email]</td>";
print "</tr>";
}
print "</table>";
}
?>
devinemke 04-02-2007, 03:03 PM <?php
mysql_connect('unix.lsbu.ac.uk', 'paleckaa', 'butteph9') or exit(mysql_error());
mysql_select_db ('paleckaa') or exit(mysql_error());
$result = mysql_query("SELECT * FROM customers WHERE customer_no = '" . $_POST['customer_no'] . "'") or exit(mysql_error());
if (mysql_num_rows($result))
{
echo '<table border="1" width="100%">';
while ($row = mysql_fetch_assoc($result))
{
echo '
<td width="10%">' . $row['customer_no'] . '</td>
<td width="30%">' . $row['first_name'] . '</td>
<td width="30%">' . $row['last_name'] . '</td>
<td width="30%">' . $row['email'] . '</td>
</tr>
';
}
echo '</table>';
}
else
{
echo 'no rows matching ' . $_POST['customer_no'];
}
?>
apalecka 04-02-2007, 03:17 PM Hi
Thank you for your fast reply! I've tried your script and it's telling me "no rows matching"? I've jst checked my database and the primary keys are customer_no so I'm very confused :)
Any advice would be much appreciated!
Thank you
Michael
devinemke 04-02-2007, 03:27 PM I've tried your script and it's telling me "no rows matching"? I've jst checked my database and the primary keys are customer_no so I'm very confused
...then you are passing a customer # that is not in the table
apalecka 04-02-2007, 03:45 PM But now I'm even more confused as every number I try from the table returns the no rows matching error, even though I've checked them...
devinemke 04-02-2007, 03:56 PM echo the query to the browser before running to make sure your POST vars are being passed as you expect them to be
apalecka 04-02-2007, 06:28 PM I'm sorry, i'm very new to this I don't know what that means :)
Thanks
michael
iLLin 04-02-2007, 06:32 PM $query = "SELECT * FROM your_table");
//$result = mysql_query($query) or die...
echo $query;
//outputs
SELECT * FROM your_table
So if you have variables in your query, you can verify that they are truly adding there values into the query. IF not you need to find out why :)
apalecka 04-02-2007, 09:06 PM Ok! Thx! But now if i put 2 into my form it returns '2' and 'no rows matching'
but there is a row for customer_no 2 in the database ... so why doesn't it returns whats in that row?
Thank a lot for ur patient for beginners!!!
Michael
aedrin 04-02-2007, 09:44 PM Do what iLLin says, and copy the SQL into a tool that directly connects to your database (phpmyadmin, MySQL Query Browser, etc.) and see what it does.
Then post the query here so we can see it.
EDIT: Also, I'd strip out the username/password from your post.
apalecka 04-04-2007, 11:29 AM Actually i tried that one and its working :) Thank you! :)
<?php
$mysql_link = mysql_connect ("xxx", "xxx", "xxx");
$testresult = mysql_select_db ("xxx", $mysql_link);
$query="SELECT * FROM customers WHERE customer_no=$_POST[customer_no]";
$query_result = mysql_query ($query, $mysql_link);
if ( mysql_num_rows ($query_result)>0) {
print"<table border=\"1\" width=\"100%\">";
while ($row = mysql_fetch_array ($query_result)) {
print "<td width=\"10%\">$row[customer_no]</td>";
print "<td width=\"30%\">$row[firstname]</td>";
print "<td width=\"30%\">$row[lastname]</td>";
print "<td width=\"30%\">$row[email]</td>";
print "</tr>";
}
print "</table>";
echo $query;
}
?>
apalecka 04-09-2007, 06:23 PM Hi so i've got that thing but how do I make validation of email( no duplikates) i tried that but its not working error says: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ... on line 10
I cannot find what the problem is. Any help would be much appreciated
Micheal
<?php
$mysql_link = mysql_connect ("xxx", "xxx", "xxx")
or die ('Unable to connect!');
$testresult = mysql_select_db ("xxx", $mysql_link)
or die ('Unable to connect database!');
$query="SELECT email FROM customers where email=$_POST[email]";
$query_result = mysql_query ($query, $mysql_link);
if ( mysql_num_rows ($query_result)>0) {
echo("This email is already registered.");
echo $query;
}
else {
$f_n = $_POST[f_n]; $l_n = $_POST[l_n]; $email = $_POST[email]; $password = $_POST[password];
$query="INSERT INTO customers (firstname, lastname, email, password)
VALUES ('$f_n', '$l_n', '$email', '$password')";
$result = mysql_query($query, $mysql_link);
echo ("$f_n Thank you for registering! Please remember your login details:<br><br>");
echo ("First name: $f_n <br>");
echo ("Last name: $l_n <br>");
echo ("Email: $email <br>");
echo ("Password: $password <br><br>");
echo ("Now try to LOG IN - click ");
echo ("<a href=http://....>here</a>");
}
?>
aedrin 04-09-2007, 06:38 PM http://www.codingforums.com/showthread.php?t=68462
apalecka 04-09-2007, 06:47 PM Oh ok! Sorry right! So once again:
--------------------------------------------------------------------------
Hi so i've got that thing but how do I make validation of email( no duplikates) i tried that but its not working error says: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ... on line 10
I cannot find what the problem is. Any help would be much appreciated
Micheal
<?php
$mysql_link = mysql_connect ("xxx", "xxx", "xxx")
or die ('Unable to connect!');
$testresult = mysql_select_db ("xxx", $mysql_link)
or die ('Unable to connect database!');
$query="SELECT email FROM customers where email=$_POST[email]";
$query_result = mysql_query ($query, $mysql_link);
if ( mysql_num_rows ($query_result)>0) {
echo("This email is already registered.");
echo $query;
}
else {
$f_n = $_POST[f_n]; $l_n = $_POST[l_n]; $email = $_POST[email]; $password = $_POST[password];
$query="INSERT INTO customers (firstname, lastname, email, password)
VALUES ('$f_n', '$l_n', '$email', '$password')";
$result = mysql_query($query, $mysql_link);
echo ("$f_n Thank you for registering! Please remember your login details:<br><br>");
echo ("First name: $f_n <br>");
echo ("Last name: $l_n <br>");
echo ("Email: $email <br>");
echo ("Password: $password <br><br>");
echo ("Now try to LOG IN - click ");
echo ("<a href=http://....>here</a>");
}
?>
|
|