Jump to content


Photo

Need Help - Probably Simple!!!


  • Please log in to reply
9 replies to this topic

#1 nashyboy

nashyboy
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 June 2006 - 07:32 AM

Hi,

Quite new to this.... Can't understand why when i add to a table and echo the sql command, it does not display the id. I have set the id field as auto_increment and primary key and adds to table correctly but when i retrieve all the data from table it doesnt show the id's....

Is there some sort of php configuration i need to change or perhaps i've set up the table uincorrect.

CREATE TABLE messages (
  id tinyint(5) NOT NULL auto_increment,
  messagestatus varchar(20) NOT NULL default '',
  time varchar(20) NOT NULL default '',
  date varchar(20) NOT NULL default '',
  requestor varchar(80) NOT NULL default '',
  requestorstatus varchar(20) NOT NULL default '',
  message blob NOT NULL,
  PRIMARY KEY  (id)
) TYPE=MyISAM;

Can someone give me some pointers?

Thanks

Paul

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 June 2006 - 07:55 AM

does an id number exist ?

echo the query out ?


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 nashyboy

nashyboy
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 June 2006 - 08:15 AM

Im using phpmyadmin and yes it does appear that the id exists and when i echo the query out after adding it from the form although it adds it to the form in phpmyadmin it echos all except the id which gets shown like this...

INSERT INTO users (id, firstname, surname, email, password) VALUES('', 'John', 'Smith' , 'john.smith@bestbitter.com' , 'smooth' )

The form code is

<form action="added_user.php" method="post">
              <table width="600" border="0" cellspacing="2" cellpadding="2">
                <tr>
                  <td width="138"><strong></strong></td>
                  <td width="462"><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">
                    <input name="id" type="hidden">
                    </font></strong></td>
                </tr>
                <tr>
                  <td><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Firstname</font></strong></td>
                  <td><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">
                    <input name="firstname" type="text" size="30" maxlength="80">
                    </font></strong></td>
                </tr>
                <tr>
                  <td><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Surname</font></strong></td>
                  <td><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">
                    <input name="surname" type="text" size="30" maxlength="80">
                    </font></strong></td>
                </tr>
                <tr>
                  <td><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Email</font></strong></td>
                  <td><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">
                    <input name="email" type="text" size="30" maxlength="80">
                    </font></strong></td>
                </tr>
                <tr>
                  <td><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Password</font></strong></td>
                  <td><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">
                    <input name="password" type="text" size="30" maxlength="20">
                    </font></strong></td>
                </tr>
                <tr>
                  <td><font color="#000000">&nbsp;</font></td>
                  <td><font color="#000000">&nbsp;</font></td>
                </tr>
                <tr>
                  <td><font color="#000000">&nbsp;</font></td>
                  <td><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">
                    <input type="reset" name="Reset" value="Reset">
                    <input name="Submit" type="submit" id="Submit" value="Submit">
                    </font></strong></td>
                </tr>
              </table>
</form>

and

the added page is...

            <?php

$id=$_POST['id'];
$firstname=$_POST['firstname'];
$surname=$_POST['surname'];
$email=$_POST['email'];
$password=$_POST['password'];

?>

<?php

include("..\includes\login_details.inc");

mysql_connect ($dbhost, $dbuser, $dbpass) or die (mysql_error()); //Connects to database

echo $dbhost. "<br/>";
echo $dbuser. "<br/>";
echo $dbpass. "<br/>";
echo $dbname. "<br/>";


mysql_select_db ($dbname) or die (mysql_error()); //Selects your database

$query = "INSERT INTO users (id, firstname, surname, email, password) VALUES('$id', '$firstname', '$surname' , '$email' , '$password' )";

echo $query. "<br/>";

$result = mysql_query($query) or die("Error: ". mysql_error());

?>

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 June 2006 - 08:27 AM

your inserting information in the database where the query to see the information fom the database.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 kals

kals
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 30 June 2006 - 08:43 AM

remove the following from the form:

<input name="id" type="hidden">

remove the following from the added page:
$id=$_POST['id'];

change the following:
$query = "INSERT INTO users (id, firstname, surname, email, password) VALUES('$id', '$firstname', '$surname' , '$email' , '$password' )";
to:
$query = "INSERT INTO users (firstname, surname, email, password) VALUES('$firstname', '$surname' , '$email' , '$password' )";

echo $query. "<br/>";

$result = mysql_query($query) or die("Error: ". mysql_error());

to view the id:
$id=mysql_insert_id($result);
echo $id;


#6 nashyboy

nashyboy
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 June 2006 - 01:18 PM

Okay thanks. I have done all that and added a new entry. When i come to edit that entry it is not parsing the id value from the results page to the edit_message.php page.

I know the hyperlink code in the results page is correct as it shows edit_message.php?id=5 in the status bar.

The current page i have to parse the value and then edit is.....

<?php

$id=$_POST['id'];

include("includes/login_details.inc");

mysql_connect ($dbhost, $dbuser, $dbpass) or die (mysql_error()); //Connects to database

mysql_select_db ($dbname) or die (mysql_error()); //Selects your database

$sql = "SELECT * FROM messages where id = '$id' ";



    $result = mysql_query($sql);

echo $sql;

    if (!$result) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
    }
   
    if (mysql_num_rows($result) == 0) {
        echo "No Messages Currently Live";

    }

    // While a row of data exists, put that row in $row as an associative array
    // Note: If you're expecting just one row, no need to use a loop
    // Note: If you put extract($row); inside the following loop, you'll
    //      then create $userid, $fullname, and $userstatus etc
    while ($row = mysql_fetch_assoc($result)) {
echo "<table width=800 border=0 cellspacing=0 cellpadding=0>
          <tr>
              <td width=25>&nbsp;</td>
              <td><font color=#00CC33 size=3 face=Georgia, Times New Roman, Times, serif><strong>Update
              Message<br>
            <form action=edited_message.php method=post>
              <table width=600 border=0 cellspacing=2 cellpadding=2>
                <tr>
                  <td width=138><strong></strong></td>
                  <td width=462><input name=id type=text value=";
        echo $row["id"];
echo "><input name=messagestatus type=text id=messagestatus value=";
        echo $row["messagestatus"];
echo "<br><strong>";
        echo $row["requestor"];
echo " | ";
        echo $row["date"];
echo " | ";
        echo $row["time"];
echo " | <font color=#0066FF><a href='edit_message.php?id=";
echo $row["id"];
echo "'>Update Message</strong></font></td>";
echo "</tr></table><br>";
    }
       
    mysql_free_result($result);

mysql_close();


?>

#7 nashyboy

nashyboy
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 June 2006 - 07:00 PM

I still having problems as per last post - can anyone help please. Cant figure it out....

#8 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 30 June 2006 - 07:08 PM

Any errors?

Orio.
Think you're smarty?

(Gone until 20 to November)

#9 nashyboy

nashyboy
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 June 2006 - 07:12 PM

nope none at all. Just not parsing the id value to the next page and displaying it even though it shows in the hyperlink of the previous.

#10 kals

kals
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 30 June 2006 - 07:49 PM

Hi,
change this:
$id=$_POST['id'];

to:
$id=$_GET['id'];

I havent gone through your entire code but that was the first thing I noticed
POST works when submitting values from forms while GET works using urls.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users