Jump to content

star_commander

Members
  • Content Count

    18
  • Joined

  • Last visited

Community Reputation

0 Neutral

About star_commander

  • Rank
    Newbie

Previous Fields

  • Languages
    Beginning PHP

Contact Methods

  • Website URL
    http://localhost
  • ICQ
    0

Profile Information

  • Interests
    Web Dev
  1. <?php$host = "localhost";$user = "test";$pass = "test";$db = "test";$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");mysql_select_db($db) or die ("Unable to select database!");$id = $_POST['id'];$vid = $_POST['vid'];$vids = mysql_query("SELECT * FROM testWHERE id='$id'") or die ("Wrong View id.");$row = mysql_fetch_array($vids);$comp = $row['vid'];$you = $row['memo'];if($vid==$comp){ if (!isset($_POST['submit'])) { ?> Your Message: <?php echo "$you"; ?> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label> <input type="text" name="edit" id="edit" /> </label> <label> <input type="submit" name="submit" id="submit" value="Edit" /> </label> </form> <?php } else { $edit = $_POST['edit']; mysql_query("DELETE FROM test WHERE id='$id'"); mysql_query("INSERT INTO test (vid, id, memo) VALUES ('$vid', '$id', '$edit')") or die ("ID has already been taken."); echo "Success!"; }}else{echo "Wrong Edit ID";}?> I don't think it's changed.
  2. The place where the POST is overwriting is in the second if statement. I tried switching to GET for the 'edit' value, but it made no difference.
  3. I can't seem to find the error in my code, but I'm sure one's there. What's causing this to happen?
  4. Thanks :)I put print_r($_POST) at the top of the code and got this as a result. Array ( [vid] => 4321 [id] => 1234 [button] => Edit! ) I tried placing print_r($GLOBALS) in various places around my script. It printed the correct variables everywhere but the second 'else' statement after the first two 'if' statements. There, new variables are stored, but they shouldn't overwrite the old ones.
  5. Notice: Undefined index: id in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\finalproject\test5.php on line 18Notice: Undefined index: vid in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\finalproject\test5.php on line 19 The values would have to exist for the test at the first 'if' statement. The 'if' statement works, for if I type in the wrong vid, I am taken to the end of the script. The values seem to disappear somewhere between the first and the second 'if' statement.
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Edit</title></head><body><?php$host = "localhost";$user = "test";$pass = "test";$db = "test";$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");mysql_select_db($db) or die ("Unable to select database!");$id = $_POST['id'];$vid = $_POST['vid'];$vids = mysql_query("SELECT * FROM testWHERE id='$id'") or die ("Wrong View id.");$row = mysql_fetch_array($vids);$comp = $row['vid'];$you = $row['memo'];if($vid==$comp){ if (!isset($_POST['submit'])) { ?> Your Message: <?php echo "$you"; ?> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label> <input type="text" name="edit" id="edit" /> </label> <label> <input type="submit" name="submit" id="submit" value="Edit" /> </label> </form> <?php } else { $edit = $_POST['edit']; echo "$you"; mysql_query("DELETE FROM test WHERE id='$id'"); mysql_query("INSERT INTO test (vid, id, memo) VALUES ('$vid', '$id', '$edit')") or die ("ID has already been taken."); echo "Success!"; print_r($GLOBALS); }}else{echo "Wrong Edit ID";}?></body></html> That's the code I'm using. [db] => test [connection] => Resource id #2 [id] => [vid] => [vids] => Resource id #3 [row] => [comp] => [you] => [edit] => test ) That's the last line of the print_r($GLOBALS) command, where the $id and $vid variables are stored.
  7. I've tried a few more things but none of them work. The queries work but the variable are empty. Does anyone know how to carry the variables, or why mine aren't working?
  8. I deleted the "or die" statement after the mysql_fetch_array() and I changed mysql_query("INSERT INTO test (vid, id, edit)VALUES ('$vid', '$id', '$memo')") or die ("ID has already been taken."); to mysql_query("INSERT INTO test (vid, id, memo) VALUES ('$vid', '$id', '$edit')") or die ("ID has already been taken."); I get the success message, but the variables I had set earlier "$id" and "$vid" are not being passed to the query, so only the message "$edit" is being stored.
  9. I am writing a script to allow editing of a message once a user name and password have been provided. The script should display a message from the database and have a text box below for a new message. Whenever I run this, I get the textbox and the message, but when I click submit, I get the "Please fill in required info error" that I had put in the script. The script goes backwards. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Edit</title></head><body><?php$host = "localhost";$user = "test";$pass = "test";$db = "test";$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");mysql_select_db($db) or die ("Unable to select database!");$id = $_POST['id'];$vid = $_POST['vid'];$vids = mysql_query("SELECT * FROM testWHERE id='$id'") or die ("Wrong View id.");$row = mysql_fetch_array($vids) or die ("Please fill in required info.");$comp = $row['vid'];$you = $row['memo'];if($vid==$comp){ if (!isset($_POST['submit'])) { ?> Your Message: <?php echo "$you"; ?> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label> <input type="text" name="edit" id="edit" /> </label> <label> <input type="submit" name="submit" id="submit" value="Edit" /> </label> </form> <?php } else { $edit = $_POST['edit']; mysql_query("DELETE FROM test WHERE id='$id'"); mysql_query("INSERT INTO test (vid, id, edit) VALUES ('$vid', '$id', '$memo')") or die ("ID has already been taken."); echo "Success"; }}else{echo "Wrong Edit ID";}?></body></html>
  10. Here's the submit page, where the forms are. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><style type="text/css"><!--.style1 {font-family: Arial, Helvetica, sans-serif}.style3 { font-family: Arial, Helvetica, sans-serif; font-size: 36px; color: #000000;}--></style></head><!-- InstanceBegin template="/Templates/templateforpro.dwt" codeOutsideHTMLIsLocked="false" --><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><!-- InstanceBeginEditable name="doctitle" --><!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --><style type="text/css"><!--body { background-color: #000000;}.style1 {color: #FFFFFF}.center {}--></style><script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script></head><body><table width="987" height="625" border="0" align="center" cellpadding="0"> <tr> <td height="139" colspan="2" valign="top" bgcolor="#FFFFFF" class="style1"><table width="979" height="132" border="0" cellpadding="0"> <tr> <td width="174" height="126"><img src="images/CSlogo.gif" alt="" width="167" height="124" /></td> <td width="787" height="126"><div align="center"><img src="images/banner.gif" alt="" width="547" height="138" /></div></td> </tr> </table></td> </tr> <!-- InstanceBeginEditable name="Region2" --> <tr> <td width="183" valign="top" bgcolor="#666666"><p> <script type="text/javascript">AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','183','height','67','src','ButtonH','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','ButtonH' ); //end AC code</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="183" height="67"> <param name="movie" value="ButtonH.swf" /> <param name="quality" value="high" /> <embed src="ButtonH.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="183" height="67"></embed> </object></noscript> </p> <p> <script type="text/javascript">AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','183','height','67','src','ButtonA','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','ButtonA' ); //end AC code</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="183" height="67"> <param name="movie" value="ButtonA.swf" /> <param name="quality" value="high" /> <embed src="ButtonA.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="183" height="67"></embed> </object></noscript> </p> <p> <script type="text/javascript">AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','183','height','67','src','ButtonS','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','ButtonS' ); //end AC code</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="183" height="67"> <param name="movie" value="ButtonS.swf" /> <param name="quality" value="high" /> <embed src="ButtonS.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="183" height="67"></embed> </object></noscript> </p> <p> <script type="text/javascript">AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','183','height','67','src','ButtonB','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','ButtonB' ); //end AC code</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="183" height="67"> <param name="movie" value="ButtonB.swf" /> <param name="quality" value="high" /> <embed src="ButtonB.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="183" height="67"></embed> </object></noscript> </p> <p> <script type="text/javascript">AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','183','height','67','src','ButtonSour','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','ButtonSour' ); //end AC code</script> <noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="183" height="67"> <param name="movie" value="ButtonSour.swf" /> <param name="quality" value="high" /> <embed src="ButtonSour.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="183" height="67"></embed> </object></noscript></p></td> <td width="798" valign="top" bgcolor="#FFFFFF"><p> </p> <p align="center"><span class="style3">About Us</span></p><p align="center">-----------------------------------------------------------------------------------------------------------</p> <p align="center"><strong>Contact Us:</strong></p> <p align="center">Use this form to send us your questions, comments, and suggestions. If you would like a response, please leave us your name and email.</p> <form id="form1" name="form1" method="post" action="test3.php"> <label> <div align="center"> <p> <input type="text" name="memo" cols="75" rows="5" id="memo"> </p> <p> <label>ID: <input name="id" type="text" id="id" size="6" /> </label> </p> <p> <label> <input type="submit" name="button" id="button" value="Submit" /> </label> <br /> </p> </div> </label> </form> <p align="center">Have a message you want to see again? Type in the unique ID you recieved to view it agian.</p> <form id="form2" name="form2" method="post" action="test4.php"> <label> <div align="center">ID: <input type="text" name="id" id="id" /> <br /> <input type="submit" name="button2" id="button2" value="Get" /> </div> </label> </form> <p align="center"> </p></td> </tr> <!-- InstanceEndEditable --></table></body><!-- InstanceEnd --></html> ----------------------------------------------------------Nevermind, I took a look at the source for my submit page and found an error. It works fine now. Thanks.
  11. The code is working. Just when I insert a value through the form, it creates a record, but the record is blank. No data is inserted into the database, but the record is created. If I manually enter information into the records through phpmyadmin then the second script works. Does anyone know what is causing this?
  12. Thanks. I'm still having problems, but I think they might have to do with the way I set up the databases. I'm pretty sure the code is correct. <?php$host = "localhost";$user = "test";$pass = "test";$db = "test";$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");mysql_select_db($db) or die ("Unable to select database!");$memo = $_POST['memo'];$id = $_POST['id'];mysql_query("INSERT INTO test (id, memo) VALUES ('$id', '$memo')") or die ("Query Failed");echo "Success";?> <?php$host = "localhost";$user = "test";$pass = "test";$db = "test";$con = mysql_connect($host, $user, $pass) or die ("Unable to connect!");mysql_select_db($db) or die ("Unable to select database!");$id = $_POST['id'];mysql_select_db("my_db", $con);$result = mysql_query("SELECT * FROM testWHERE id='$id'");while($row = mysql_fetch_array($result)) { echo $row['id'] . " " . $row['memo']; echo "<br />"; } ?>
  13. I use Firefox. I switched to it due to security reasons and stayed because of tabbed browsing and add-ons.
  14. Ok, thanks. I didn't catch those stupid mistakes. $result = mysql_query("SELECT * FROM testWHERE id='"$id"'"); Does this code work? Can I pull a row from a variable set by the user by doing this?
  15. I have a text box for users to input text. Below that is another box to input a number. When they click submit, the variables are stored in the database. There is also another forum with a field where they can input their "id" number they set earlier and pull up their message. This is just a script I am making to learn PHP and Mysql.
×
×
  • Create New...