Jump to content

PHP help - Updating a mysql database with forms


iJoseph

Recommended Posts

I have the following code, (I'm sorry it's so long an it does more that the question asks.)

 

It's ment to edit, delete and make new links in a mysql database, by also using a link header to home all the links (Like a dropdown menu) And thig manages the links. However then the update, or when the new form is submitted it leaves then titlereg field blank. (The titlereg is the id of the main link, it's called reg in the title_reg database) I know this is complicated and i'm not too good at explaining the problem but any help would be great. I have commented on anything that could help.

<?php
include "../includes/mysql_connect.php";
include "../includes/info_files.php";

echo "<strong>Links</strong><br />";
echo "Currect links:<br /><br />";

if($_POST['submit']){

$name = mysql_real_escape_string($_POST['name']);
$titlereg = mysql_real_escape_string($_POST['titlereg']);
$url = mysql_real_escape_string($_POST['url']);
$id = mysql_real_escape_string($_POST['id']);

mysql_query("UPDATE nav_sub SET name='$name', SET titlereg='$titlereg', SET url='$url' WHERE reg='$id'"); ////////////////////////////////// Here will help, the update MY SQL thingie
echo "Link Changed.<br /><br />";
}
elseif($_POST['remove']){

$id = mysql_real_escape_string($_POST['id']);

mysql_query("DELETE FROM nav_sub WHERE reg='$id'");
echo "Link deleted.<br /><br />";
}
else{
$result = mysql_query("SELECT * FROM nav_sub");

while($row = mysql_fetch_array($result))
  {
echo '<strong>' . $row['name'] . '</strong>';
echo '<form action="" method="post">';
echo 'Name: <input type="text" name="name" value="' . $row['name'] . '" /><br />';
echo 'Link: <input type="text" name="text" value="' . $row['url'] . '" /><br />';
echo 'Navigation title: <select name="titlereg">';

$resultabc = mysql_query("SELECT * FROM nav_title");

while($rowabc = mysql_fetch_array($resultabc))
  {

echo '<option value="' . $rowabc['reg'] . '">' . $rowabc['name'] . '</option>'; ////////////////////////////////// Here is the option
  
  }
echo '</select>';
echo '<input type="hidden" name="id" value="' . $row['reg'] . '" />';
echo '<input type="submit" name="submit" value="Change" /> <input type="submit" name="remove" value="Remove" /><br />';
echo '</form>';
  }
}

echo "New link:<br /><br />";

if($_POST['new_submit']){ ////////////////////////////////// Here!!!!!!!!!!!!!!!
$result = mysql_query("SELECT * FROM nav_sub");

$new_titlereg = $_POST['new_titlereg'];
$new_name = mysql_real_escape_string($_POST['new_name']);
$new_url = mysql_real_escape_string($_POST['new_url']);

mysql_query("INSERT INTO `nav_sub` (`titlereg` ,`reg` ,`name` ,`url`)VALUES ('$new_titlereg', '', '$new_name', '$new_url')"); ////////////////////////////////// here is the MY SQL statement...
echo "Link added.<br /><br />";
}

echo '<form action="" method="post">';
echo 'Name: <input type="text" name="new_name" value="" /><br />';
echo 'Url: <input type="text" name="new_url" value="" /> \\\\ If your linking to a page you made, then the url is index.php?catt=(The categrory you put)&page=(The page you put)<br />';
echo 'Navigation title: <select name="new_titlereg">';

$resultab = mysql_query("SELECT * FROM nav_title");

while($rowab = mysql_fetch_array($resultab))
  {

echo '<option value="' . $rowab['reg'] . '">' . $rowab['name'] . '</option>'; ////////////////////////////////// Here isn't submitting the value in the option
  
  }
echo '</select>';
echo '<input type="submit" name="new_submit" value="Insert" /><br />';
echo '</form>';
?>

 

By the way, explain simply as I'm only 13 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.