Jump to content

eric11

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Posts posted by eric11

  1. 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>

  2. You never said what trouble you were having. I ran your script and the only thing I get is 'about.html' not found.

     

    Is about.html in the same folder as this program? Does the program write to the screen? The only two thing that might cause the redirect to not work.

     

     

    sorry, didn't clarify well. the error that comes up is

    Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web221/b2217/d5.ericlee/public_html/remarch/insert.php:10) in /hermes/bosweb/web221/b2217/d5.ericlee/public_html/remarch/insert.php on line 29
    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 :)

  3. 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

    header('Location: about.html');
    .

    Would be appreciated if someone could give me some guidance :)

     

    Thank you in advance!

  4. 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

    UPDATE orders SET Name='TEST', Location='TEST', Fault='TEST', Completed='1', WHERE id = 1

    Update query failed

    Query: {$query}

    Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = 1' at line 1Array ( [ud_id] => 1 [ud_name] => TEST [ud_location] => TEST [ud_fault] => TEST [ud_completed] => 1 )

     

    Your explanation makes sense.. in that i should be using $query because i defined it already.. but doesn't seem to work out.. :(

  5. 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)
    
    ?> 

  6. thanks Buddski for having a look

     

    1. i dont think i am.. but.. not quite sure what to do..

    2.

    CREATE TABLE `orders` (

      `Name` varchar(30) NOT NULL,

      `Location` varchar(30) NOT NULL,

      `Fault` varchar(30) NOT NULL,

      `Description` longtext NOT NULL,

      `Time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,

      `Date` date NOT NULL,

      `Completed` tinyint(1) NOT NULL

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

     

    any help would be appreciated.. Sorry im a little new to the syntax of PHP.

  7. i inserted the WHERE like you asked me to.

    it came out with

    UPDATE orders SET Name='TEST', Location='TEST', Fault='TEST', Completed='1', WHERE id =

    Update query failed

    Query: {$query}

    Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id =' at line 1Array ( [ud_id] => [ud_name] => TEST [ud_location] => TEST [ud_fault] => TEST [ud_completed] => 1 )

     

    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']}"; 

  8. Thanks :)

     

    We're getting close! When i deleted the

    WHERE 'id'=''
    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!

  9. thanks for that, you helped get rid of the errors it now says:

    UPDATE orders SET Name='TEST', Location='TEST', Fault='TEST', Completed='1' WHERE 'id'=''

    update query succeededArray ( [ud_id] => [ud_name] => TEST [ud_location] => TEST [ud_fault] => TEST [ud_completed] => 1 )

     

    but.. seems like it's not updating on the database itself..

     

    anything else I could try?

     

  10. Thanks for the reply and explanation,

     

    I think i got what you said about the first bit with the ``

     

    however, when you said

    You are passing the text "id" instead of the id value from the database.
    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 :P

  11. 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

     

  12. 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.