Jump to content

php mysql errors


devang23

Recommended Posts

i have 2 scripts and one of them is to send info into mysql and the other one is to display it.

 

the problem with this script is that the page just refreshes, and i believe it doesnt store the information that im trying to store.

 

<html><head><title>Adding a User </title></head>
<body>
<?php
if( (!$firstname) or (!$lastname) or (!$username) or (!$password) )
{
$form ="Please enter all new user details";
$form.="<form action=\"$PHP_SELF\"";
$form.=" method=\"post\">First Name: ";
$form.="<input type=\"text\" name=\firstname\"";
$form.=" value=\"$firstname\"><br>Last Name: ";
$form.="<input type=\"text\" name=\"lastname\"";
$form.=" value=\"$lastname\"><br>UserName: ";
$form.="<input type=\"text\" name=\"username\"";
$form.=" value=\"$username\"><br>PassWord: ";
$form.="<input type=\"text\" name=\"password\"";
$form.=" value=\"$password\"><br>";
$form.="<input type=\"submit\" value=\"Submit\">";
$form.="</form>";
echo($form);
}
else
{ $conn = mysql_connect("mysql4.000webhost.com","a3213677_dolphin","******")or die("Try Again Punk");
  $db = mysql_select_db("a3213677_snorre",$conn)or die("NOOPE");
  $sql = "insert into User Table (first_name,last_name,username,password) values (\"$firstname\",\"$lastname\",\"$username\",password(\"$password\") )";
  $result = mysql_query($sql,$conn);
if($result) { echo("New User $username ADDED DUH"); }
}
?> </body></html>

 

and the 2nd one i get this error message "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''User Table' Where 1' at line 1"

 

<html><head><title>I'm a GENUIS</title></head>
<body>
<?php

$conn=mysql_connect("mysql4.000webhost.com","a3213677_dolphin","********") or die(mysql_error());
$rs = mysql_select_db("a3213677_snorre", $conn) or die("NOOOPE");
$sql="select * from 'User Table' Where 1";
$rs=mysql_query($sql,$conn) or die(mysql_error());;

$list = "<table border=\"1\" cellpadding=\"2\">";
$list.="<tr><th><First Name</th>";
$list.="<th>Last Name</th>";
$list.="<th>UserName</th>";
$list.="<th>PassWord</th></tr>";

while($row= mysql_fetch_array($rs) )
{
$list .= "<tr>";
$list .= "<td>".$row["first_name"]."</td>";
$list .= "<td>".$row["last_name"]."</td>";
$list .= "<td>".$row["username"]."</td>";
$list .= "<td>".$row["password"]."</td>";
$list .= "</tr>";
}
$list .= "<\table";

echo($list);

?>
</body><html>

Link to comment
Share on other sites

Try this for the second code, it might work.

 

Also, whats the problem with the first code?

 

<html><head><title>I'm a GENUIS</title></head>
<body>
<?php

$conn=mysql_connect("mysql4.000webhost.com","a3213677_dolphin","********") or die(mysql_error());
$rs = mysql_select_db("a3213677_snorre", $conn) or die("NOOOPE");
$sql="select * from `User Table` Where 1";
$rs=mysql_query($sql,$conn) or die(mysql_error());;

$list = "<table border=\"1\" cellpadding=\"2\">";
$list.="<tr><th><First Name</th>";
$list.="<th>Last Name</th>";
$list.="<th>UserName</th>";
$list.="<th>PassWord</th></tr>";

while($row= mysql_fetch_array($rs) )
{
$list .= "<tr>";
$list .= "<td>".$row["first_name"]."</td>";
$list .= "<td>".$row["last_name"]."</td>";
$list .= "<td>".$row["username"]."</td>";
$list .= "<td>".$row["password"]."</td>";
$list .= "</tr>";
}
$list .= "<\table";

echo($list);

?>
</body><html>

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.