needdd help here.....plssssssssss
Posted: Sat Mar 15, 2008 11:52 pm
Everah | Please use proper code tags when posting code in the forums. You may use [code], [php], [{lang}] or [syntax="{lang}"] where {lang} is the language you want to highlight. Your post has been edited to show how we would like to see it.
it can't insert data to my database, don't know y..i'm a real newbie....using php 5 and mysql 5
Everah | Please use proper code tags when posting code in the forums. You may use [code], [php], [{lang}] or [syntax="{lang}"] where {lang} is the language you want to highlight. Your post has been edited to show how we would like to see it.
it can't insert data to my database, don't know y..i'm a real newbie....using php 5 and mysql 5
Code: Select all
<?php
session_start();
//echo"<h1>Member only</h1>";
?>
<body>
<?php
if (session_is_registered("valid_user"))
{
//echo "<br><br>Welcome <b><font color=\"green\">$valid_user</font></b> <br>";
?>
<table align="center"><tr>
<td><?php include "menu.inc"; //include this as menu ?></td>
</tr>
<tr>
<td>
<?php
function new_items(){
echo "<center><b>POST YOUR ITEMS HERE</b></center>";
echo "<center><b>Please fill in this form to post items</b></center>";
echo "<form name=newitems method=post action=\"additem.php?act=add\">\n";
echo "<table>";
echo "<tr valign=top>\n";
echo "<td align=right><b>Item name :</b></td>";
echo "<td>";
echo " <input class=\"inputbox\" type=\"text\" name=\"item_name\">";
echo "</td>";
echo "</tr>\n";
echo "<tr valign=top>\n";
echo "<td align=right><b>Category :</b></td>";
echo "<td>";
echo " <select name=\"item_cat\">";
echo " <option selected>Engine and performance</option>";
echo " <option>Wheels and chasis</option>";
echo " <option>Exterior and body</option>";
echo " </select>";
echo "</td>";
echo "</tr>\n";
echo "<tr valign=top>\n";
echo "<td align=right><b>Condition :</b></td>";
echo "<td>";
echo " <input class=\"inputbox\" type=\"text\" name=\"item_cond\">";
echo "</td>";
echo "</tr>\n";
echo "<tr valign=top>\n";
echo "<td align=right><b>Price :</b></td>";
echo "<td>";
echo " <input class=\"inputbox\" type=\"text\" name=\"item_price\">";
echo "</td>";
echo "</tr>\n";
echo "<tr valign=top>\n";
echo "<td align=right><b>Your name :</b></td>";
echo "<td>";
echo " <input class=\"inputbox\" type=\"text\" name=\"supp_name\">";
echo "</td>";
echo "</tr>\n";
echo "<tr valign=top>\n";
echo "<td align=right><b>Your contact No :</b></td>";
echo "<td>";
echo " <input class=\"inputbox\" type=\"text\" name=\"supp_cont\">";
echo "</td>";
echo "</tr>\n";
echo "<tr><td colspan=2 align=center>\n";
echo "<input type=submit name=Submit value=\"SAVE\">\n";
echo "<input type=reset name=Submit2 value=\"RESET\">\n";
echo "</td></tr>\n";
echo "</form>\n";
echo "</table>\n";
} // end function new_items
function add_items(){
global $id,$item_name,$item_cat,$item_cond,$item_price,$supp_name,$supp_cont;
$DbServer = "localhost"; //server
$DbUser = "root"; //my username, you should change this
$DbPass = "awesliuk"; //my password, you should change this either
$DbName = "project_elective"; //this is my database name..in MySQL
// make connection to database
$dblink=mysql_connect($DbServer, $DbUser, $DbPass) OR DIE("Unable to connect to database");
@mysql_select_db("$DbName") or die( "Unable to select database");
$query="insert into items (id,item_name,item_cat,item_cond,item_price,supp_name,supp_cont) VALUES ('$id','$item_name','$item_cat','$item_cond','$item_price','$supp_name','$supp_cont')";
$result = mysql_query($query);
echo "<br><br><br><center>Thank You..your item has been saved</center>\n";
} // end function add_items
switch($act) {
case "add":
add_items();
break;
default:
new_items();
break;
}
}
else
{
echo "<br>You are not logged in.<br>";
echo "Only logged in members may see this page.<br><br>";
echo "<a href =\"index.php\">Back to login</a>";
}
?>