Jump to content

eric11

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

eric11's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. ahh cool. thanks for the clarification. thanks all of you! appreciated heaps
  2. on line 10 its just a <?php i tried putting up the header before that.. however.. similar errors still show up. at the moment i have: <body> <?php header('Location: about.html'); ?> <?php $link = mysql_connect('.com', 'xxx', 'xxx'); if (!$link) { die('Could not connect: ' . mysql_error()); } //echo 'Connected successfully'; mysql_select_db('remarch', $link); $sql="INSERT INTO posts (Name, Location, Fault, Other, Description) VALUES ('$_POST[name]','$_POST[location]','$_POST[fault]','$_POST[other]','$_POST[description]')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } mysql_close($link); ?> </body>
  3. sorry, didn't clarify well. the error that comes up is or whatever line the header is at. the 'about.html' page is located in the same folder... i was able to solve almost the same issue in another script/page i have.. but for this page... it's not working.. ><" the program does not write to the screen... simply, once the form is submitted... it will redirect to the about page automatically. any other ideas? thanks guys
  4. Hi, I'm having trouble with redirect my page to another page. what I have is a page that uses a form to insert into a database, the form is then processed to another page (insert.php) which will insert the information inserted in the form. I'm trying to work out how I could redirect the user to another page once the data has been successfully inserted. this is what I have now: insert.php <?php $link = mysql_connect('ericlee.dot5hostingmysql.com', 'user', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } //echo 'Connected successfully'; mysql_select_db('remarch', $link); $sql="INSERT INTO posts (Name, Location, Fault, Other, Description) VALUES ('$_POST[name]','$_POST[location]','$_POST[fault]','$_POST[other]','$_POST[description]')"; header('Location: about.html'); if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } mysql_close($link); ?> I'm pretty sure it's just the placing of the code . Would be appreciated if someone could give me some guidance Thank you in advance!
  5. you legend! all fixed i love you! thanks for all the support guys. i really really appreciate it.
  6. I've replaced the code and fixed up the table. but now the update page is blank. I tried putting back the code I had before, but came up with the same error msg Your explanation makes sense.. in that i should be using $query because i defined it already.. but doesn't seem to work out..
  7. this is what i have at the moment: update.php $id = $_GET['id']; // Ask the database for the information from the orders table $query="SELECT * FROM orders WHERE id='$id'"; $result = mysql_query("SELECT * FROM orders"); if(!$result) { echo "Query failed<br>Query: {$query}<br>Error: " . mysql_error(); } else { //Create an update form for each order while($order = mysql_fetch_assoc($result)) { echo "<form action='updated.php' method='post'>\n"; echo "<input type='text' name='ud_id' value='{$order['id']}'>\n"; echo "Name: <input type='text' name='ud_name' value='{$order['Name']}'><br>\n"; echo "Location: <input type='text' name='ud_location' value='{$order['Location']}'><br>\n"; echo "Fault: <input type='text' name='ud_fault' value='{$order['Fault']}'><br>\n"; echo "Completed: <input type='text' name='ud_completed' value='{$order['Completed']}'><br>\n"; echo "<input type='Submit' value='Update'>\n"; echo "</form>\n"; } } ?> updated.php $query="UPDATE orders SET Name='{$_POST['ud_name']}', Location='{$_POST['ud_location']}', Fault='{$_POST['ud_fault']}', Completed='{$_POST['ud_completed']}', WHERE id = {$_POST['ud_id']}"; echo $query; $checkresult = mysql_query($query); if ($checkresult) { echo '<p>update query succeeded'; } else { echo '<p>Update query failed<br>Query: {$query}<br>Error: ' . mysql_error(); } print_r($_POST) ?>
  8. thanks Buddski for having a look 1. i dont think i am.. but.. not quite sure what to do.. 2. any help would be appreciated.. Sorry im a little new to the syntax of PHP.
  9. yeah, coming up with the same error.. :S would a count(); be useful for this? not sure.. tqtq
  10. i inserted the WHERE like you asked me to. it came out with this is right, right? $query="UPDATE orders SET Name='{$_POST['ud_name']}', Location='{$_POST['ud_location']}', Fault='{$_POST['ud_fault']}', Completed='{$_POST['ud_completed']}', WHERE id = {$_POST['ud_id']}";
  11. Thanks We're getting close! When i deleted the it updated the database. for example, changed 'Completed=0' to 'Completed=1' the result was that it changed the database value. but it changed ALL of the rows instead of the specific row I wanted to change. Here is what I have at the moment: update.php $id = $_GET['id']; // Ask the database for the information from the orders table $query="SELECT * FROM orders WHERE id='$id'"; $result = mysql_query("SELECT * FROM orders"); if(!$result) { echo "Query failed<br>Query: {$query}<br>Error: " . mysql_error(); } else { //Create an update form for each order while($order = mysql_fetch_assoc($result)) { echo "<form action='updated.php' method='post'>\n"; echo "<input type='hidden' name='ud_id' value='{$order['id']}'>\n"; echo "Name: <input type='text' name='ud_name' value='{$order['Name']}'><br>\n"; echo "Location: <input type='text' name='ud_location' value='{$order['Location']}'><br>\n"; echo "Fault: <input type='text' name='ud_fault' value='{$order['Fault']}'><br>\n"; echo "Completed: <input type='text' name='ud_completed' value='{$order['Completed']}'><br>\n"; echo "<input type='Submit' value='Update'>\n"; echo "</form>\n"; } } ?> updated.php <?php // Connect to the database $link = mysql_connect('ericlee.dot5hostingmysql.com', 'eric', '11111'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('fixitdb', $link); [color=red]$query="UPDATE orders SET Name='{$_POST['ud_name']}', Location='{$_POST['ud_location']}', Fault='{$_POST['ud_fault']}', Completed='{$_POST['ud_completed']}'"; [/color] echo $query; $checkresult = mysql_query($query); if ($checkresult) { echo '<p>update query succeeded'; } else { echo '<p>Update query failed<br>Query: {$query}<br>Error: ' . mysql_error(); } print_r($_POST) ?> Thankyou!
  12. thanks for that, you helped get rid of the errors it now says: but.. seems like it's not updating on the database itself.. anything else I could try?
  13. Thanks for the reply and explanation, I think i got what you said about the first bit with the `` however, when you said i got a little lost with how I could implement that into my code. Sorry, I'm pretty horrible with the syntax of PHP. but i think it has to do with these 2 sets of code: update.php $query="SELECT * FROM orders WHERE id='$id'"; updated.php $query="UPDATE orders SET Name='{$_POST['ud_name']}', Location='{$_POST['ud_location']}', Fault='{$_POST['ud_fault']}' WHERE `id`='{$_POST[`ud_id`]}'"; I just cant get it through my head :'( Thanks for helping mate, I should pay you
  14. thanks for the reply! I've followed your instructions and tested it out (thanks for making the code simpler btw) when attempting to update the fields on the 'updated.php' page, it echoes "UPDATE orders SET Name='Name', Location='ee', Fault='Fault' WHERE id='id' Update query failed Query: {$query} Error: Unknown column 'id' in 'where clause'Array ( [ud_id] => id [ud_name] => Name [ud_location] => ee [ud_fault] => Fault )" So I'm thinking that it has to do with the WHERE id $query="UPDATE orders SET Name='{$_POST['ud_name']}', Location='{$_POST['ud_location']}', Fault='{$_POST['ud_fault']}' WHERE id='{$_POST['ud_id']}'"; that is there. Been playing around with it for a while now... not sure what I can put in there.. but this is what I have atm: ------------------------------------- update.php page $id = $_GET['id']; // Ask the database for the information from the orders table $query = "SELECT 'id', 'Name', 'Location', 'Fault' FROM orders"; $result = mysql_query($query); if(!$result) { echo "Query failed<br>Query: {$query}<br>Error: " . mysql_error(); } else { //Create an update form for each order while($order = mysql_fetch_assoc($result)) { echo "<form action='updated.php' method='post'>\n"; echo "<input type='hidden' name='ud_id' value='{$order['id']}'>\n"; echo "Name: <input type='text' name='ud_name' value='{$order['Name']}'><br>\n"; echo "Location: <input type='text' name='ud_location' value='{$order['Location']}'><br>\n"; echo "Fault: <input type='text' name='ud_fault' value='{$order['Fault']}'><br>\n"; echo "<input type='Submit' value='Update'>\n"; echo "</form>\n"; } } ?> ------------------------------------- updated.php $query="UPDATE orders SET Name='{$_POST['ud_name']}', Location='{$_POST['ud_location']}', Fault='{$_POST['ud_fault']}' WHERE id='{$_POST['ud_id']}'"; echo $query; $checkresult = mysql_query($query); if ($checkresult) { echo '<p>update query succeeded'; } else { echo '<p>Update query failed<br>Query: {$query}<br>Error: ' . mysql_error(); } print_r($_POST) ?> ------------------------------------- thank you so much for your help
  15. Hi, Im just in the middle of creating an update script for my mysql database but don't know why it's not working. p.s. I'm a little new to PHP, but know quite a bit, it's probably something really small.. *facepalm* Here's the script: the form (update.php) <? // Connect to the database $link = mysql_connect('###', '###', '###'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('###', $link); $id = $_GET['id']; // Ask the database for the information from the links table $query="SELECT * FROM orders WHERE id='$id'"; $result = mysql_query("SELECT * FROM orders"); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $name=mysql_result($result,$i,"Name"); $location=mysql_result($result,$i,"Location"); $fault=mysql_result($result,$i,"Fault"); ?> <form action="updated.php" method="post"> <input type="hidden" name="ud_id" value="<? echo "$id";?>"> Name: <input type="text" name="ud_name" value="<? echo "$name"?>"><br> Location: <input type="text" name="ud_location" value="<? echo "$location"?>"><br> Fault: <input type="text" name="ud_fault" value="<? echo "$fault"?>"><br> <input type="Submit" value="Update"> </form> <? ++$i; } ?> ------------------------------------------------------ (processor) updated.php <?php // Connect to the database $link = mysql_connect('###', '###', '###'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('###', $link); $query="UPDATE orders SET Name='" . $_POST['ud_name'] . "', Location='" . $_POST['ud_location'] . "', Fault='" . $_POST['ud_fault'] . "' WHERE $id='" . $_POST['ud_id'] . "'"; echo $query; $checkresult = mysql_query($query); if ($checkresult) echo '<p>update query succeeded'; else echo '<p>update query failed'; mysql_close(); ?> ------------------------------------------------------ Every time I want to update, it comes up with: UPDATE orders SET Name='TEST', Location='TEST', fault='jbjh' WHERE ='' update query failed Any help would be appreciated.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.