killfall Posted July 31, 2008 Share Posted July 31, 2008 Hi there, Im having a few problems with updating a SQL database. I have 1 page which had information on it which has been pulled from the database and I have made it so you can edit the information and then update the database with the new info. I have done this with 2 pages, 1 with a form on it, then a submit page which sends the information using the $_POST method, but for some reason the submit page cant access the $_POST and comes up blank. Main Page: <? if(isset($_GET['id'])){ $jobid = $_GET['id']; setcookie("BaseIDTemp", $jobid); } else { header('Location:http://base.kaedo-online.net/view.php'); } $logon = $_COOKIE['basedata123']; if($logon == 'valid'){ } else { header('Location:http://base.kaedo-online.net/'); } include 'dbconnect.php'; $query = mysql_query("SELECT * FROM base WHERE jobid = $jobid") or die(Error); while ($row = mysql_fetch_assoc($query)) { $title=$row["title"]; $forename=$row["forename"]; $surname=$row["surname"]; $phone=$row["phone"]; $altphone=$row["altphone"]; $model=$row["model"]; $os=$row["os"]; $oemraw=$row["oem"]; $machineage=$row["machineage"]; $address=$row["address"]; $billing=$row["billing"]; } mysql_free_result($query); if (isset($oemraw)){ list($oem1, $oem2, $oem3, $oem4, $oem5) = explode("-", $oemraw); } else { } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Base Computers Customer Database</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- .style1 { font-family: Arial, Helvetica, sans-serif; font-weight: bold; } a:link { text-decoration: none; color:#000000; } a:visited { text-decoration: none; color: #000000; } a:hover { text-decoration: underline; color: #3399FF; } a:active { text-decoration: none; } .style4 {font-family: Arial, Helvetica, sans-serif; color: #000000; } .style7 {font-family: Arial, Helvetica, sans-serif} --> </style> </head> <body> <table width="100%" border="0"> <tr> <td align="left" valign="top"><span class="style1">Base Computers Customer Database</span></td> <td rowspan="2" align="right" valign="top"><img src="logo.jpg" width="400" height="100"></td> </tr> <tr> <td align="left" valign="top"><p><span class="style4"><a href="view.php">Home</a></span><span class="style4"><a href="logout.php"></a></span></p> <p><span class="style4"><a href="add.php">Add </a></span></p> <p><span class="style4"><a href="logout.php">Logout</a></span></p></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr valign="top"> <td colspan="2"><form name="Modify" method="post" action="/modifycustomer.php"> <table width="100%" border="0"> <tr> <td><span class="style7">Title</span></td> <td><p> <select name="Title" id="select"> <? if($title == 'Mr'){ echo '<option selected>Mr</option> <option>Mrs</option> <option>Miss</option> <option>Ms</option>'; } elseif($title == 'Mrs'){ echo '<option>Mr</option> <option selected>Mrs</option> <option>Miss</option> <option>Ms</option>'; } elseif($title == 'Miss'){ echo '<option>Mr</option> <option>Mrs</option> <option selected>Miss</option> <option>Ms</option>'; } elseif($title == 'Ms'){ echo '<option>Mr</option> <option>Mrs</option> <option>Miss</option> <option selected>Ms</option>'; } else { echo '<option>Mr</option> <option>Mrs</option> <option>Miss</option> <option>Ms</option>'; } ?> </select> </p> </td> <td rowspan="4"><span class="style7">Address</span></td> <td rowspan="4"><textarea name="Address" id="textarea"><? echo $address ?></textarea></td> </tr> <tr> <td><span class="style7">Forename</span></td> <td><input name="Forename" type="text" id="Forename3" value="<? echo $forename ?>"></td> </tr> <tr> <td><span class="style7">Surname</span></td> <td><input name="Surname" type="text" id="Surname3" value="<? echo $surname ?>"></td> </tr> <tr> <td><span class="style7">Phone No </span></td> <td><input name="Phone" type="text" id="Phone3" value="<? echo $phone ?>"></td> </tr> <tr> <td><span class="style7">Alt Phone No </span></td> <td><input name="Other Phone" type="text" id="Other Phone3" value="<? echo $altphone ?>"></td> <td rowspan="5"><span class="style7">Billing Address </span></td> <td rowspan="5"><textarea name="Billing Address" id="textarea2"><? echo $billing ?></textarea></td> </tr> <tr> <td><span class="style7">Make/Model</span></td> <td><input name="Make/Model" type="text" id="Make/Model3" value="<? echo $model ?>"></td> </tr> <tr> <td><span class="style7">OS</span></td> <td><input name="OS" type="text" id="OS3" value="<? echo $os ?>"></td> </tr> <tr> <td><span class="style7">OEM</span></td> <td><input name="OEM1" type="text" id="OEM17" value="<? echo $oem1 ?>" size="5" maxlength="5"> <input name="OEM2" type="text" id="OEM23" value="<? echo $oem2 ?>" size="5" maxlength="5"> <input name="OEM3" type="text" id="OEM32" value="<? echo $oem3 ?>" size="5" maxlength="5"> <input name="OEM4" type="text" id="OEM42" value="<? echo $oem4 ?>" size="5" maxlength="5"> <input name="OEM5" type="text" id="OEM52" value="<? echo $oem5 ?>" size="5" maxlength="5"></td> </tr> <tr> <td><span class="style7">Machine Age </span></td> <td><input name="Machine Age" type="text" id="Machine Age3" value="<? echo $machineage ?>"></td> </tr> <tr align="right"> <td colspan="4"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form></td> </tr> </table> </body> <? include 'dbdisconnect.php' ?> </html> Submit Page: <? include 'dbconnect.php'; if(isset($_POST['Modify'])){ $oem = $_POST['oem1'].'-'.$_POST['oem2'].'-'.$_POST['oem3'].'-'.$_POST['oem4'].'-'.$_POST['oem5']; $title = $_POST['title']; $forename = $_POST['forename']; $surname = $_POST['surname']; $address = $_POST['address']; $billing = $_POST['billing']; $phone = $_POST['phone']; $altphone = $_POST['altphone']; $model = $_POST['model']; $os = $_POST['os']; $machineage = $_POST['machineage']; $warranty = $_POST['warranty']; $job = $_POST['job']; $jobid = $_COOKIE['BaseIDTemp']; $query = "UPDATE base SET title = '$title', forename = '$forename', surname = '$surname', address = '$address', billing = '$billing', phone = '$phone', altphone = '$altphone', model = '$model', oem = '$oem', os = '$os', machineage = '$machineage', warranty = '$warranty', job = '$job'". "WHERE jobid = $jobid"; mysql_query($query) or die('Error, insert query failed'); echo 'User Added Successfully, you will now be redirected'; } else { echo 'fail'; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Submit</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <META http-equiv="refresh" content="1;URL=http://base.kaedo-online.net/view.php"> </head> <body> </body> </html> Quote Link to comment Share on other sites More sharing options...
MaaSTaaR Posted August 1, 2008 Share Posted August 1, 2008 Hello ... In the head of submit page add : print_r($_POST); and tell us what is the result. Quote Link to comment Share on other sites More sharing options...
killfall Posted August 1, 2008 Author Share Posted August 1, 2008 It says fail still Quote Link to comment Share on other sites More sharing options...
mikePhp Posted August 1, 2008 Share Posted August 1, 2008 $query = "UPDATE base SET title = '$title', forename = '$forename', surname = '$surname', address = '$address', billing = '$billing', phone = '$phone', altphone = '$altphone', model = '$model', oem = '$oem', os = '$os', machineage = '$machineage', warranty = '$warranty', job = '$job'". "WHERE jobid = $jobid"; Why are you separating the WHERE clause from the rest of the SQL and then attaching it again...? You have no need to to end the QUERY after your $job variable. Not sure if this is going to make a difference to why your having a fail response but try it like this NOTICE AT THE END ASWELL $query = "UPDATE base SET title = '$title', forename = '$forename', surname = '$surname', address = '$address', billing = '$billing', phone = '$phone', altphone = '$altphone', model = '$model', oem = '$oem', os = '$os', machineage = '$machineage', warranty = '$warranty', job = '$job' WHERE base.jobid = '$jobid'"; Quote Link to comment Share on other sites More sharing options...
paul2463 Posted August 1, 2008 Share Posted August 1, 2008 print_r($_POST) should have printed out what is in the $_POST array, it will still fail in your query because nothing has changed - did oyu not get an echoed out result of the print_r() function??? Quote Link to comment Share on other sites More sharing options...
killfall Posted August 1, 2008 Author Share Posted August 1, 2008 nope, but that may be because i put the function in the IF statement, when I have access to my machine later I'll try again and post the results. I cant at the mo as I'm at work. Quote Link to comment Share on other sites More sharing options...
killfall Posted August 1, 2008 Author Share Posted August 1, 2008 Thanks for your help guys. Just me makin silly mistakes, I had names all the fields wrong, using capitals etc. I had this problem before with the add page but forgot to change the modify page. 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.