Jump to content

Gondie

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Everything posted by Gondie

  1. I will try that. And as of my previous posts sorry, I was mistaken. I had not completed the dropdown and it is not functioning properly. Thank you, this is resolved! The error was in assigning the $num variable with the wrong $POST_ entry.
  2. But it still sends the $cat variable from an option menu of the same format echo "<select name=\"cat\">\n"; $conn = mysql_connect("localhost", "$username", "$password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("$database")) { echo "Unable to select $database: " . mysql_error(); exit; } $sql = "SELECT * FROM siteNavCats"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo "<option value='"; echo $row['num']; echo "'>"; echo $row['name']; echo "</option>"; } echo "</select>"; ?> Options have No name field, only an ID field. I have tried entering the ID as the 'num' value but it did not work.
  3. Thank you for pointing out the missing '=' I had completely missed it, but that is not the issue at hand. I am sorry fugix but I seem to be misunderstanding something. The form is set up to POST the value selected TO the next page, which contains the next form. That is why I had to declare the $num variable form the $POST_ data. Below is the same method which I have implemented on another page, which instead of being used to Edit an entry it is to create one. So do not get this confused with the php I have posted earlier. This is simply to state that it does function as I believe. <form method="post" action="pageinsert.php"><br /> <input name="name" type="text" class="form1" value="About Us" maxlength="20" id="name" /><br /><br /> <input name="desc" type="text" class="form1" value="Learn more about us" maxlength="100" id="desc" /><br /><br /><br /> <input name="title" type="text" class="form1" value="About Us" maxlength="100" id="desc" /><br /><br /><br /> <?php include "config.php"; echo "<select name=\"cat\">\n"; $conn = mysql_connect("localhost", "$username", "$password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("$database")) { echo "Unable to select $database: " . mysql_error(); exit; } $sql = "SELECT * FROM siteNavCats"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo "<option value='"; echo $row['num']; echo "'>"; echo $row['name']; echo "</option>"; } echo "</select>"; ?> <br /><br /><br /> <input type="hidden" name="num" value="1" /> <center><input type="submit" /><input type="reset" /></center> </form Which is sent to the following, and works flawlessly: <? include "config.php"; $num=$_NUM['num']; $name=$_POST['name']; $desc=$_POST['desc']; $title=$_POST['title']; $cat=$_POST['cat']; $con = mysql_connect("localhost","$username","$password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$database", $con); $sql="INSERT INTO sitePages VALUES ('$num','$name','$desc','$title','cat')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "$name $desc $title $cat"; echo "Added Page"; mysql_close($con); $url = htmlspecialchars($_SERVER['HTTP_REFERER']); echo "<br><br><a href='$url'>back</a>"; ?> Now, if I am still missing something I am sorry.
  4. As I stated in my origional post: It is the same number that is being entered as the options 'value'.
  5. echo "<option value='"; echo $row['num']; echo "'>"; echo $row['num']; echo " - "; echo $row['name']; echo "</option>"; Shouldnt the value be accepted rather than the name in this case? The above code creates this dropdown
  6. echo $_POST['num']; $num=$_POST['num']; These 2 lines. I only copied the error from the first, but they both produce it. When it executes the query it returns the function for no rows found if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; If I alter the code so that it does not use a variable to search the database, instead using (for example) 1, it performs the query flawlessly.
  7. Iv tried asking a lot of people and have had no luck resolving this issue, so I will try here. I have created a Form which gathers its information from a Database. The first form is a Dropdown Option, which when submitted takes you to another page. The new page is Supposed to use the value from the Dropdown to search the database and return the proper rows to populate a few text areas to edit the values. This is where I am stuck. Compared to what most of you create this is probably sloppy and not too well structured, but I am new to this. Anyways, I will provide more information below now. The following is the initial page with the first form. This is where you would select what page you wish to edit. (I believe this may be where the issue resides) - (I included the 'num' value before the 'name' value so that I could see it is getting the value from the database, which it is) <form method="post" action="pageedit.php"><br /> <?php include "config.php"; echo "<select name=\"page\">\n"; $conn = mysql_connect("localhost", "$username", "$password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("$database")) { echo "Unable to select $database: " . mysql_error(); exit; } $sql = "SELECT * FROM sitePages"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo "<option value='"; echo $row['num']; echo "'>"; echo $row['num']; echo " - "; echo $row['name']; echo "</option>"; } echo "</select>"; ?> <br /> <input type="submit" /> </form> And then the following is the page that the form is sent to when submitted: (I have attempted to Echo the 'num' value sent so that I could verify that it is indeed sent, but it is not. I will post the message I receive after the PHP snippet <form method="post" action="pageeditinsert.php"><br /> <?php include "config.php"; echo $_POST['num']; $num=$_POST['num']; $conn = mysql_connect("localhost", "$username", "$password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("$database")) { echo "Unable to select $database: " . mysql_error(); exit; } $sql = "SELECT * FROM sitepages WHERE num = '$num'"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo "<input name'num' type='hidden' class='form1' value='"; echo $num; echo "' maxlength='10' id='cat' /><br /><br /><br />"; echo "<input name='name' type='text' class='form1' value='"; echo $row['name']; echo "' maxlength='20' id='name' /><br /><br />"; echo "<input name='desc' type='text' class='form1' value='"; echo $row['desc']; echo "' maxlength='100' id='desc' /><br /><br /><br />"; echo "<input name='title' type='text' class='form1' value='"; echo $row['title']; echo "' maxlength='100' id='title' /><br /><br /><br />"; echo "<input name'cat' type='hidden' class='form1' value='cat' maxlength='3' id='cat' /><br /><br /><br />"; } ?> <br /><br /><br /> <center><input type="submit" /><input type="reset" /></center> </form> Below is the message I receive when attempting to echo the POSTed 'num' value: (I am running the latest WAMP release on my personal PC for testing purposes until I have finished this and upload it to my hosting server) Anyways thanks for your time. Hopefully someone has an idea for me.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.