Lee-Bartlett Posted September 28, 2008 Share Posted September 28, 2008 I followed this TUT online and i cant see what i got wrong, <?php require_once("includes/db_connection.php") ?> <?php //If cmd has not been initialized if(!isset($cmd)) { //display all the business $result = mysql_query("select * from tblbasicform by email"); //run the while loop that grabs all the business scripts while($r=mysql_fetch_array($result)); { //grab the business_name and the username of the business $email=$r["email"];//take out the business_name $name=$r["name"];//take out the username //make the business_name a link echo "<a href='edit.php?cmd=edit&username=$username'>$business_name - Edit</a>"; // echo "<br>"; } } ?> <? if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") { if (!isset($_POST["submit"])) { $name= $_GET["name"]; $sql = "SELECT * FROM tblbasicform WHERE name='$name'"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form action="edit.php" method="post"> <input type=hidden name="username" value="<?php echo $myrow["name"] ?>"> business_name:<INPUT TYPE="TEXT" NAME="email" VALUE="<?php echo $myrow["email"] ?>" SIZE=30><br> info:<TEXTAREA NAME="locaiton" ROWS=10 COLS=30><? echo $myrow["location"] ?></TEXTAREA><br> industry:<INPUT TYPE="TEXT" NAME="buissnes_name" VALUE="<?php echo $myrow["buissnes_name"] ?>" SIZE=30><br> <input type="hidden" name="cmd" value="edit"> <input type="submit" name="submit" value="submit"> </form> <? } ?> <? if ($_POST["$submit"]) { $email = $_POST["email"]; $location = $_POST["location"]; $buissnes_name = $_POST["buissnes_name"]; $sql = "UPDATE tblbasicform SET email='$email',location='$location', buissnes_name='$buissnes_name' WHERE name='$name'"; $result = mysql_query($sql); echo "Thank you! Information updated."; } } ?> i get this error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Website\attempt.php on line 16 Quote Link to comment Share on other sites More sharing options...
CroNiX Posted September 28, 2008 Share Posted September 28, 2008 Doesn't look like you have a connection established. Post the code from db_connection.php. You can block out the username/password etc, but we need to see how its connecting (or not). Quote Link to comment Share on other sites More sharing options...
Lee-Bartlett Posted September 28, 2008 Author Share Posted September 28, 2008 <?php $db_host = "localhost"; // Your database host server, eg. db.server.com $db_user = "takenout"; // User who has access to the database $db_pass = "takenout"; // User password to access database $db_name = "roberts_work"; // Existing database name // -- Connecting to the database (not persistent connection) $connect = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name,$connect) or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
CroNiX Posted September 28, 2008 Share Posted September 28, 2008 change: <?php $connect = mysql_connect($db_host, $db_user, $db_pass); to this: <?php $connect = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error()); and see if you get an error Quote Link to comment Share on other sites More sharing options...
Lee-Bartlett Posted September 28, 2008 Author Share Posted September 28, 2008 im getting a connection, thats the thing, its line 16 while($r= mysql_fetch_array($result)); ive tested the connection Quote Link to comment Share on other sites More sharing options...
CroNiX Posted September 28, 2008 Share Posted September 28, 2008 Ah, the problem seems to be in your query: <?php $result = mysql_query("select * from tblbasicform by email"); I think you want 'ORDER BY email'. <?php $result = mysql_query("select * from tblbasicform ORDER BY email") or die(mysql_error()); also adding the die after will show you if there is a problem in your query... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.