Page 1 of 1

needdd help here.....plssssssssss

Posted: Sat Mar 15, 2008 11:52 pm
by silentcloud18
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>";
        }
        
?>
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.

Re: needdd help here.....plssssssssss

Posted: Mon Mar 17, 2008 10:18 am
by pickle
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
Moving post to PHP Code. Please wrap your code in tags as well so it's readable.

Re: needdd help here.....plssssssssss

Posted: Mon Mar 17, 2008 10:27 am
by RobertGonzalez
Why not try using a mysql_error() call after the query so the database server can tell you what's wrong with it. If there is nothing wrong with the query turn on display_errors so you can see what PHP is telling you.

Re: needdd help here.....plssssssssss

Posted: Mon Mar 17, 2008 10:06 pm
by nincha
change:
$result = mysql_query($query);
to
$result = mysql_query($query) or die(mysql_error());

Re: needdd help here.....plssssssssss

Posted: Mon Mar 17, 2008 10:17 pm
by Christopher
And:

Code: Select all

$result = mysql_query($query);
if (mysql_errno()) {
     echo 'Error: ' . mysql_error();
}

Re: needdd help here.....plssssssssss

Posted: Wed Mar 26, 2008 10:14 am
by silentcloud18
here is the file, if its alright with you guys...help me with my prob..

Re: needdd help here.....plssssssssss

Posted: Wed Mar 26, 2008 10:19 am
by John Cartwright
Run the file with the changes that were suggested and post the results. Nobody is going to do the work for you.