Jump to content

Error with two table?


tshing70
 Share

Recommended Posts

Hi guys, i got a question again.....thank for help anyway~ Ok, i have two table in edit.php which is newmember and collection, newmember is use too edit user info such as name, gender etc,collection is use too add date, amount and references no, WHEN I SUCCESSFUL ADD THE INFO AT COLLECTION TABLE, IT GOES BACK TO EDIT.PHPTHE NEWMEMBER TABLE BEEN ERROR SHOW ME Undefined index: id in C:\wamp\www\edit.php on line 16Undefined variable: gender in C:\wamp\www\edit.php on line 63 Call Stack #TimeMemoryFunctionLocation 11.7753382928{main}( )..\edit.php:0 " name="gender"/>Undefined variable: dob in C:\wamp\www\edit.php on line 65 Call Stack #TimeMemoryFunctionLocation 11.7753382928{main}( )..\edit.php:0 " name="dob" class="tcal"/>etc.... BUT MY COLLECTION TABLE WORK FINE, ONLY NEWMEMBER TABLE ERROR, WAT IS THE PROBLEMEDIT.PHP<center><html><head><title>Edit Form</title><link rel="stylesheet" type="text/css" href="tcal.css" /><script type="text/javascript" src="tcal.js"></script></head><body><?php$con = mysql_connect("localhost","root","");if (!$con){die('Could not connect: ' . mysql_error());} $id = $_GET["id"]; mysql_select_db("member_db", $con); $sql = "SELECT * FROM newmember Where P_Id=$id";$query = mysql_query($sql); while ($row = mysql_fetch_array($query)){ $id = $row['P_Id'];$name = $row['Name'];$gender = $row['Gender']; $dob = $row['Dob'];$address = $row['Address'];$state = $row['State']; }mysql_free_result($query);?> <form action="update.php" method="post"><table width="250" border="1"> <tr valign="top"><td style="background-color:white;width:100px;text-align:top;"> Id<p>Name<p>Gender<p>Dob<p>Address<p>State</td><td style="background-color:#EEEEEE;height:200px;width:1000px;text-align:top;"><p><input type="text" value="<?php echo $id;?>" name="id" disabled/><p><input type="text" value="<?php echo $name;?>" name="name"/><p><input type="text" value="<?php echo $gender;?>" name="gender"/><p><input type="text" value="<?php echo $dob;?>" name="dob" class="tcal"/><p><input type="text" value="<?php echo $address;?>" name="address"/><p><input type="text" value="<?php echo $state;?>" name="state"/><p><input type = "submit" value="EDIT"/></table></form></body></html> <FORM method ="GET" action = "add.html"><input type = "submit" value = "Add"> <?php$con = mysql_connect ("localhost","root","");if (!$con){die('Could not connect: ' .mysql_error());}mysql_select_db("member_db", $con); $result = mysql_query("SELECT * FROM collection"); echo "<table border ='1'><tr><th>Id</th><th>Date</th><th>RefNo</th><th>Amount</th></tr>"; while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td>" . $row['C_Id'] ."</td>";echo "<td>" . $row['date'] ."</td>";echo "<td>" . $row['refno'] ."</td>";echo "<td>" . $row['amount'] ."</td>";echo ("<td><a href=\"edit1.php?id=$row[C_Id]\">Edit</a></td>");echo ("<td><a href=\"delete1.php?id=$row[C_Id]\">Delete</a></td></tr>");} echo "</table>"; mysql_close($con); ?></FORM> ADD.php<?php $con = mysql_connect("localhost","root","");if (!$con){die('Could not connect: ' . mysql_error());} mysql_select_db("member_db", $con); $sql="INSERT INTO collection (date, refno, amount) VALUES ('$_POST[date]','$_POST[refno]','$_POST[amount]')"; if (!mysql_query($sql,$con)){die('Error: ' . mysql_error());}echo "1 record added";echo "<br>";echo "<a href='edit.php'>Back to Edit page</a>"; mysql_close($con);?> Thank for finish this long code, thank to everyone thank you~~~

Link to comment
Share on other sites

for Edit.phpremove the double quotes and use single quotes (thats how it should be writen as far as i know)so it should be$id = $_GET['id']; instead of $id = $_GET["id"];also you have a open <td> tag but its not close tho, its the second <td> tag you open and if you follow the code you'll see that its not close also the <tr> isnt close either, should close these up. whats wrong with the add.php? you didnt say if anything was wrong with it or not, or maybe i over looked that. but this is what i can give so far hope it help

Link to comment
Share on other sites

for Edit.phpremove the double quotes and use single quotes (thats how it should be writen as far as i know)so it should be$id = $_GET['id']; instead of $id = $_GET["id"];also you have a open <td> tag but its not close tho, its the second <td> tag you open and if you follow the code you'll see that its not close also the <tr> isnt close either, should close these up. whats wrong with the add.php? you didnt say if anything was wrong with it or not, or maybe i over looked that. but this is what i can give so far hope it help
thank for reply, actually my error is thiswhen i go in the edit.phpI got newmember and collection table at 1 form, both work fine will show the info,but i add some info to collection table, which is add.php code to add the info, then back to edit.php form, the collection table work fine, successful add the info, but my newmember table completely error, show the Undefined index: id ,date, genderi believe maybe is add.php return variable got some wrong, but i can't figure out .....
Link to comment
Share on other sites

thank for reply,actually my error is thiswhen i go in the edit.phpI got newmember and collection table at 1 form, both work fine will show the info,but i add some info to collection table, which is add.php code to add the info, then back to edit.php form,the collection table work fine, successful add the info, but my newmember table completely error, show the Undefined index: id ,date, genderi believe maybe is add.php return variable got some wrong, but i can't figure out .....
the problem is in the edit.php, it tells you where the error is located in the error message, so therefore the error is being output in the edit.php, thats why i told you what i have saw in the code.did you try doing what i said? if not please do so, and then upload the file back into the www folder for wamp and see if you get any other error, then copy and paste the error here with the updated script for edit.php
Link to comment
Share on other sites

wait do you have a gender column in your collection table? also you should check if theres a id in that table also, maybe you put it in the table as collect_id or just id, you should check your database table also to make sure your pulling the correct collumns

Link to comment
Share on other sites

Question: why are you displaying the id from the database in the edit.php form? #imjustcurious

Link to comment
Share on other sites

in your add.php the back link of edit.php does not have passed id so that $_GET has not id indexed defined. that is the reason od first error. so that $id is getting NULL. for that reason the while loop is not executing cause it has returned 0 rows. so the intialiation of gender is also did not happened. that is what rest of the error means. You can always check the returned row using var_dump($row) to be sure what you are getting from db if it is returning any. Also there is no reason to use table to layout the page. You can interpolate array directly into strings like echo "<td>{ $row['amount'] }</td>"; $_GET['id'] and $_GET["id"] both will work correctly. differences in quote is, double quote will evaluate value of any variable inside it , single quote wont. both are strings.

Edited by birbal
Link to comment
Share on other sites

ok you have P_Id then you have C_Id, do you have both these id's in your database? if no, log into your database and check and see exactly which one you have and if you have the P_Id only then use P_Id viseverse

Link to comment
Share on other sites

$_GET['id'] and $_GET["id"] both will work correctly. differences in quote is, double quote will evaluate value of any variable inside it , single quote wont. both are strings.
ok, i learned something new today, but i perfer to go with single quotes, it works better for me
Link to comment
Share on other sites

it is best to use single quote if your string does not need to do evaluate value of variable. double quotes looks for variables resolving so it is slower. though this difference is VERY NEGLIGIBLE. but it is always better not to use anything if you don't need to.

Edited by birbal
Link to comment
Share on other sites

it is best to use single quote if your string does not need to do evaluate value of variable. double quotes looks for variables resolving so it is slower. though this difference is VERY NEGLIGIBLE. but it is always better not to use anything if you don't need to.
oh ok, thanks for the additional knowledge birbal
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...