you probably think im crazy as i know this is a easy question but i cannot work it out at all. I was here all night working out a silly error and realised i was just inserting data and then asking to display the data in a table without telling it what to display - doh
anyway i have got my php adding to my database, i just need it to echo the table, so i need a select * from customer but i already have a $query = insert .... into ..... and then...

$result = mysql_query($query);
$numrows = mysql_num_rows($result);

            if ($numrows == 0) {
	    echo "No data to display!";
	    exit;
	}
	echo ?>
	<table border="1"><tr><th>firstName</th><th>lastName</th><th>address</th><th>dateOfBirth</th><th>telephoneNo</th></tr>
	  <?
	  while($row = mysql_fetch_assoc($result))
	  {
	  ?>
	<tr><td><input type="text" value="<? echo $row["firstName"] ?></td><td><? echo $row["lastName"] ?></td><td><? echo $row["address"] ?></td><td><? echo $row["dateOfBirth"] ?></td><td><? echo $row["telephoneNo"] ?>">
	</td></tr><?}?>

so where can i say select * from customer to actually display the updated table?
i'm baffled!

    noobyphpchick wrote:

    but i already have a $query = insert .... into

    That doesn't matter - execute the query and then write a new one. Example:

    $query = 'INSERT INTO myTable VALUES (1, 2, ...)';
    $exec = mysql_query($query);
    // anything else you need to do after INSERT'ing the data here...
    
    $query = 'SELECT col1, col2 FROM myTable';
    $exec = mysql_query($query);

    I would recommend you SELECT only the columns that you need data from rather than using the "SELECT *" statement.

      i've done that and it brings an error which is slightly weird - well for me πŸ˜•
      can anyone shed any light? thaaaaaaaaaaaaaankyoooooou x

      Error : Operand should contain 1 column(s)

      when my parathesis on my sql query is like...

      $sql = "INSERT INTO customer (firstName, lastName, address, dateOfBirth, telephoneNo)
      VALUES
      ('$_POST[firstName]','$_POST[lastName]','$_POST[address]','$_POST[dateOfBirth]','$_POST[telephoneNo]')";
      
      $sql = "select ('$_POST[firstName]','$_POST[lastName]','$_POST[address]','$_POST[dateOfBirth]', '$_POST[telephoneNo]') from customer";
      $result = mysql_query($sql);

      and this error when they have the brackets in the select...

      Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\indigoperl\apache\htdocs\videoshop\makecustomer.php on line 113

        You $sql string for the Select statement is wrong.

        You need to select the fields from the database table:

        $sql = "SELECT firstName, lastName, address, dateOfBirth, telephoneNo FROM customer";

        and not the posted values like you are doing at the moment

        $sql = "select ('$POST[firstName]','$POST[lastName]','$POST[address]','$POST[dateOfBirth]', '$_POST[telephoneNo]') from customer";

          You also need to execute the first query before you overwrite the $sql variable with the second query.

          Also, you should never place user-supplied data directly into a SQL query. Instead, you should sanitize it with a function such as [man]mysql_real_escape_string/man.

            Thank you thats really helpful, i def have a lot of learning to do, i have managed to get it workingπŸ™‚:evilgrin: πŸ™‚

              Write a Reply...