Jump to content


php menu via Mysql


4 replies to this topic

#1 teco

    Young Padawan

  • Members
  • Pip
  • 3 posts
  • Gender:Male
  • Location:Denmark

Posted 26 May 2005 - 10:55 AM

Hello friends!

I´m building a CMS for my own site and i´m searching for at tutorial that can learn me how to store my site menu via the Mysql database, does anybody know where to find such one or do anyone of you have such a system ??

Regards teco

#2 fiv3isaliv3

    Young Padawan

  • Members
  • Pip
  • 258 posts
  • Gender:Male

Posted 26 May 2005 - 04:32 PM

i'm guessing you mean you want to store the site navigation in a table so you can update/delete stuff via your CMS. you'd simply store the information like you would store any information. so just look for a tutorial that covers inserting information into mysql and use the techniques covered accordingly.

#3 teco

    Young Padawan

  • Members
  • Pip
  • 3 posts
  • Gender:Male
  • Location:Denmark

Posted 27 May 2005 - 06:15 AM

zealivity5, on May 26 2005, 09:32 PM, said:

i'm guessing you mean you want to store the site navigation in a table so you can update/delete stuff via your CMS. you'd simply store the information like you would store any information. so just look for a tutorial that covers inserting information into mysql and use the techniques covered accordingly.
Yes that was my idea, well just gotta find such tut, and thx for the help zealivity5

#4 fiv3isaliv3

    Young Padawan

  • Members
  • Pip
  • 258 posts
  • Gender:Male

Posted 27 May 2005 - 03:12 PM

ah what the hell here you go. first off you'll need a form. as you can see there is some php in there. this is because i have an earlier query (this is from my site) to include information from a table that pertains to the post. you would use this same concept to edit something but i'll get to the details of that later on.

<form action="index.php?page=post" method="post" />

<h1>
<input type='hidden' value='contact' name='type' />
<p>name:</p>
<p><input type="text" name="name" /></p>
<p>website:</p>
<p><input type="text" name="website" /></p>
<p>email:</p>
<p><input type="text" name="email" /></p>
<p>message:</p>
<p><textarea name="com" rows="6" cols="45"><?php echo "$message"; ?></textarea></p>
<p><input type="submit" name="contact" value="send" /></p>
</h1>

</form>

okay now that we have the form lets say the user hits "send" this will take us to the next page. (you can also post to the page you are on but i don't generally do that).

if (ISSET($_POST[contact])){

$year = date("Y");
$day = date("l");
$month = date("F");
$num_date = date("dS");
$ip = getenv("REMOTE_ADDR");

$insert = mysql_query("INSERT INTO comments (article_id,website,email,author,body,date,num_date,day,month,year,ip,type) VALUES ('".$_GET["id"]."','".$_POST["website"]."','".$_POST["email"]."','".$_POST["name"]."','".$_POST["com"]."','$day $month $num_date $year','$num_date','$day','$month','$year','$ip','".$_POST["type"]."')") or die('error inserting comment '.mysql_error());
echo "<META META HTTP-EQUIV=Refresh CONTENT='1; URL=index.php?page=contact&amp;post=true'>";
}

okay this code isn't the best it is just somthing simple i worked up. first i'll go over what it does. all the variables at the top are just various information such as date an ip. in the actual query you'll see $_POST["website"] etc that is the information that was entered in the form. after that query the page will refresh to either the same page if you want or a different page.

okay now that you understand the basics of a form and inserting information you'd do this to now edit that same information.

$query = mysql_query("SELECT * FROM nav") or die("error selecting info ".mysql_error());
while ($list = mysql_fetch_object($query)){
echo "$list->info";

alright what you are trying to do can be accomplished a few different ways. the way i generally like to edit information is to do this. i'll create a link such as index.php?page=edit&id=$list->id and then i'll do a query such as the one above. then i'll make another page with the form such as the one at the top and i'll do this.


$id = $_GET['id'];

$query = mysql_query("SELECT * FROM nav WHERE id='$id'") or die("error selecting info ".mysql_error());
while ($list = mysql_fetch_object($query)){

this is what your form would end up looking like to reflect the information that was stored that you'd want to edit.

<form action="index.php?page=post" method="post" />

<h1>
<input type='hidden' value='contact' name='type' />
<p>name:</p>
<p><input type="text" name="name" value="<?php echo "$list->name"; ?> /></p>
<p>website:</p>
<p><input type="text" name="website" value="<?php echo "$list->website"; ?> /></p>
<p>email:</p>
<p><input type="text" name="email" value="<?php echo "$list->email"; ?> /></p>
<p>message:</p>
<p><textarea name="com" rows="6" cols="45"><?php echo "$list->message"; ?></textarea></p>
<p><input type="submit" name="contact" value="send" /></p>
</h1>

</form>

hope all that makes sense...

#5 teco

    Young Padawan

  • Members
  • Pip
  • 3 posts
  • Gender:Male
  • Location:Denmark

Posted 28 May 2005 - 02:35 AM

Hey thx man, i'll play arround with the code a little and make it work for my own site :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users