nashyboy Posted June 30, 2006 Share Posted June 30, 2006 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?ThanksPaul Quote Link to comment https://forums.phpfreaks.com/topic/13269-need-help-probably-simple/ Share on other sites More sharing options...
redarrow Posted June 30, 2006 Share Posted June 30, 2006 does an id number exist ?echo the query out ? Quote Link to comment https://forums.phpfreaks.com/topic/13269-need-help-probably-simple/#findComment-51088 Share on other sites More sharing options...
nashyboy Posted June 30, 2006 Author Share Posted June 30, 2006 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"> </font></td> <td><font color="#000000"> </font></td> </tr> <tr> <td><font color="#000000"> </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>andthe 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());?> Quote Link to comment https://forums.phpfreaks.com/topic/13269-need-help-probably-simple/#findComment-51091 Share on other sites More sharing options...
redarrow Posted June 30, 2006 Share Posted June 30, 2006 your inserting information in the database where the query to see the information fom the database. Quote Link to comment https://forums.phpfreaks.com/topic/13269-need-help-probably-simple/#findComment-51094 Share on other sites More sharing options...
kals Posted June 30, 2006 Share Posted June 30, 2006 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; Quote Link to comment https://forums.phpfreaks.com/topic/13269-need-help-probably-simple/#findComment-51102 Share on other sites More sharing options...
nashyboy Posted June 30, 2006 Author Share Posted June 30, 2006 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> </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();?> Quote Link to comment https://forums.phpfreaks.com/topic/13269-need-help-probably-simple/#findComment-51204 Share on other sites More sharing options...
nashyboy Posted June 30, 2006 Author Share Posted June 30, 2006 I still having problems as per last post - can anyone help please. Cant figure it out.... Quote Link to comment https://forums.phpfreaks.com/topic/13269-need-help-probably-simple/#findComment-51386 Share on other sites More sharing options...
Orio Posted June 30, 2006 Share Posted June 30, 2006 Any errors?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/13269-need-help-probably-simple/#findComment-51390 Share on other sites More sharing options...
nashyboy Posted June 30, 2006 Author Share Posted June 30, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13269-need-help-probably-simple/#findComment-51392 Share on other sites More sharing options...
kals Posted June 30, 2006 Share Posted June 30, 2006 Hi,change this:$id=$_POST['id'];to:$id=$_GET['id'];I havent gone through your entire code but that was the first thing I noticedPOST works when submitting values from forms while GET works using urls. Quote Link to comment https://forums.phpfreaks.com/topic/13269-need-help-probably-simple/#findComment-51405 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.