flexsingh Posted March 30, 2008 Share Posted March 30, 2008 Hello there, I am getting a error message when updating a table, I have split the process into three pages. The first creates the form for the user to choose a court. <?php // this starts the session session_start(); ?> <html> <br> <br> <head> <h1><font face="sans-serif, Arial" font color="white">Update Court Page!</h1> </head> <br> <br> <br> <br> <br> <br> <br> <br> <body background="main background1.jpg" link="blue" vlink="blue"> <table width="350" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td> <table width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td colspan="3" align="center"><strong><font face="sans-serif, Arial" font color="white">Please Choose A Court</strong></td> </tr> <tr> <td><form id="form1" name="form1" method="post"><font face="sans-serif, Arial" font color="white">Court No</td> <td><font color="white">:</td> <td><select name="court" id="court"> <option>-----------------------</option> <option value="Fcourt1">Football court 1</option> <option value="Fcourt2">Football court 2</option> <option value="Bcourt">Basketball court </option> </select> <input type="submit" name="Submit" value="Submit"/> </form> </td> </tr> </table> <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { $court = $_POST['court']; switch ($court) { case "Fcourt1": require_once("fcourt1.php"); //echo $var; break; Case "Fcourt2": require_once("fcourt2.php"); //echo $var; break; Case "Bcourt": require_once("bcourt.php"); //echo $var; break; } } ?> </body> </html> This bit works fine and no problems, I then go to a add on page where they choose a time and only the times where member no = 0 is shown, this works fine as well. <html> <head> </head> <?php $db_name="project"; // Database name $tbl_name="bcourt"; // Table name // Connect to server and select database. $conn = mysql_connect($_SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); ?> <body background="main background1.jpg" link="blue" vlink="blue"> <table width="350" border="1" align="center" cellpadding="0" cellspacing="1"> <tr> <td><form name="Update Network Gaming form" method="post" action="updatebcourt_ac.php"> <table width="100%" border="1" cellspacing="1" cellpadding="3"> <tr> <td colspan="3" align="center"><strong><font face="sans-serif, Arial" font color="white">Insert Data Into mySQL Database </strong></td> </tr> <tr> <td><font face="sans-serif, Arial" font color="white">Member No</td> <td><font color="white">:</td> <td><input name="Member_No" type="int" id="Member_No"></td> </tr> <tr> <td><font face="sans-serif, Arial" font color="white">Court No</td> <td><font color="white">:</td> <td><input name="Court_No" type="varchar" id="Court_No" value="Bcourt"></td> </tr> <tr> <td><font face="sans-serif, Arial" font color="white">Time Slot No</td> <td><font color="white">:</td> <td><select> <?php $db_name="project"; // Database name $tbl_name="bcourt"; // Table name // Connect to server and select database. $conn = mysql_connect($_SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect"); mysql_select_db("$db_name", $conn)or die("cannot select DB"); $memberno2=urlencode($_GET['Member_No']); $time=urlencode($_GET['Time_Slot_No']); $time = "SELECT Time_Slot_No FROM $tbl_name WHERE Member_No = '0'"; $query = mysql_query($time, $conn); // do the query while($queryColumn=mysql_fetch_assoc($query)){ // fetch each row in the result set $val=$queryColumn['Time_Slot_No']; // make it simpler echo "<option value='$val'>$val</option>"; // construct option statement } ?> </select></td> </tr> <td colspan="3" align="center"><input type="submit" name="Submit" value="Continue"></td> </tr> </table> </form> </td> </tr> </table> </body> </html> After they have chosen the time then click submit and this is where I require the database to not create but update the time field and it changes member no to whatever member number was chosen, then that court can not be chosen next time round unless it was cancelled. When I had it creating the data it worked but updating it just fails with no error message. <?php // this starts the session session_start(); ?> <?php $db_name="project"; // Database name $tbl_name="bcourt"; // Table name // Connect to server and select database. mysql_connect($_SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $memberno1=$_POST['Member_No']; $courtno1=$_POST['Court_No']; $TSN1=$_POST['Time_Slot_No']; $memberno2=urldecode($_GET['Member_No']); $time=urldecode($_GET['Time_Slot_No']); // Insert data into mysql $query = ("UPDATE $tbl_name SET Member_No = $memberno1 WHERE Time_Slot_No = '".$_GET["Time_Slot_No"]."' LIMIT 1"); $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ header('Location: blank.php'); } else { echo "ERROR"; } // close connection mysql_close(); ?> I feel I am close but something is missing as it will not update. If anyone has any ideas that could be of assistance it would be much appriciated. Thank you in advanced. Link to comment https://forums.phpfreaks.com/topic/98686-update-error/ Share on other sites More sharing options...
BlueSkyIS Posted March 30, 2008 Share Posted March 30, 2008 "I am getting a error message when updating a table" ....and the error message is.....? Link to comment https://forums.phpfreaks.com/topic/98686-update-error/#findComment-505050 Share on other sites More sharing options...
lewis987 Posted March 30, 2008 Share Posted March 30, 2008 Its the SQL you've used... $query = ("UPDATE $tbl_name SET Member_No = $memberno1 WHERE Time_Slot_No = '".$_GET["Time_Slot_No"]."' LIMIT 1"); Should be: $query = "UPDATE `".$tbl_name."` SET `Member_No` = '".$memberno1."' WHERE `Time_Slot_No` = '".$_GET["Time_Slot_No"]."' LIMIT 1"; Link to comment https://forums.phpfreaks.com/topic/98686-update-error/#findComment-505051 Share on other sites More sharing options...
flexsingh Posted March 30, 2008 Author Share Posted March 30, 2008 "I am getting a error message when updating a table" ....and the error message is.....? I just asked it to echo error if cant complete, im guessing its error is at the end as it cannot update the table. Have I done it right? Maybe I do not need these: - $memberno2=urldecode($_GET['Member_No']); $time=urldecode($_GET['Time_Slot_No']); I'm just not sure. I can update fine when not getting data from other pages so I though I would need these and would need to recall them. Link to comment https://forums.phpfreaks.com/topic/98686-update-error/#findComment-505054 Share on other sites More sharing options...
flexsingh Posted March 30, 2008 Author Share Posted March 30, 2008 Its the SQL you've used... $query = ("UPDATE $tbl_name SET Member_No = $memberno1 WHERE Time_Slot_No = '".$_GET["Time_Slot_No"]."' LIMIT 1"); Should be: $query = "UPDATE `".$tbl_name."` SET `Member_No` = '".$memberno1."' WHERE `Time_Slot_No` = '".$_GET["Time_Slot_No"]."' LIMIT 1"; I'm still getting a error as it can't update, thank you for trying to help though. Link to comment https://forums.phpfreaks.com/topic/98686-update-error/#findComment-505059 Share on other sites More sharing options...
BlueSkyIS Posted March 30, 2008 Share Posted March 30, 2008 yes, there is no requirement for backticks there. here is the problem. you set $query = to the SQL query, but then execute something completely different, $sql. $query = "UPDATE $tbl_name SET Member_No = '$memberno1' WHERE Time_Slot_No = '".$_GET["Time_Slot_No"]."' LIMIT 1"; $result=mysql_query($query) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/98686-update-error/#findComment-505064 Share on other sites More sharing options...
flexsingh Posted March 30, 2008 Author Share Posted March 30, 2008 yes, there is no requirement for backticks there. here is the problem. you set $query = to the SQL query, but then execute something completely different, $sql. $query = "UPDATE $tbl_name SET Member_No = '$memberno1' WHERE Time_Slot_No = '".$_GET["Time_Slot_No"]."' LIMIT 1"; $result=mysql_query($query) or die(mysql_error()); Thank you very much for that. It is updating now but it's just always updating timeslot '0' no matter which I choose. I'll have to try all the combinations of retrieving time slot I think. You have been really helpful thank you. Link to comment https://forums.phpfreaks.com/topic/98686-update-error/#findComment-505077 Share on other sites More sharing options...
BlueSkyIS Posted March 30, 2008 Share Posted March 30, 2008 i would echo $query; before the mysql_query() to see if it looks right. you may not be getting $_GET["Time_Slot_No"] Link to comment https://forums.phpfreaks.com/topic/98686-update-error/#findComment-505090 Share on other sites More sharing options...
flexsingh Posted March 30, 2008 Author Share Posted March 30, 2008 i would echo $query; before the mysql_query() to see if it looks right. you may not be getting $_GET["Time_Slot_No"] Yep your exactly right it was not finding the time slot number, the echo I was getting was "UPDATE bcourt SET Member_No = '2' WHERE Time_Slot_No = '' LIMIT 1" Link to comment https://forums.phpfreaks.com/topic/98686-update-error/#findComment-505107 Share on other sites More sharing options...
flexsingh Posted March 30, 2008 Author Share Posted March 30, 2008 i would echo $query; before the mysql_query() to see if it looks right. you may not be getting $_GET["Time_Slot_No"] I can't seem to find the problem, sorry do you see something I might have missed? T Thank you for your help so far. Link to comment https://forums.phpfreaks.com/topic/98686-update-error/#findComment-505132 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.