sungpeng Posted April 9, 2009 Share Posted April 9, 2009 <?php if($_POST[action]=="Submit") { include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/config.php"); $loginname=$_POST[loginname]; echo "$loginname"; $insert_student="insert into users ('llid','loginname') values ('3','$loginname')"; mysql_query($insert_student) or die ("cannot insert"); ?> <?php }else{ ?> <?php include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/header.php"); ?> <html> <head> <title>Agents Register</title> </head> <body> <table width="400" align="center"> <br> <form name="form" action="<?php print $PHP_SELF ?>" onSubmit="return validate(this);" method="post"> <tr> <td width="35%">Loginname</td> <td><input type="text" name="loginname" size="25"></td> </tr> <tr> <td align="center" colspan="2"><input type="submit" name="action" value="Submit"></td> </tr> </table> </form> </body> </html> <?php } ?> Can anyone help, I don't know why simple script why cannot work? always show cannot insert Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/ Share on other sites More sharing options...
dadamssg Posted April 9, 2009 Share Posted April 9, 2009 first...state your problem, what exactly is happening that you don't want...then state what you do want.. but try this...you have many unnecessary <?php and ?> tags <?php if($_POST[action]=="Submit") { include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/config.php"); $loginname=$_POST[loginname]; echo "$loginname"; $insert_student="insert into users ('llid','loginname') values ('3','$loginname')"; mysql_query($insert_student) or die ("cannot insert"); }else{ include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/header.php")} ?> <html> <head> <title>Agents Register</title> </head> <body> <table width="400" align="center"> <br> <form name="form" action="<?php print $PHP_SELF ?>" onSubmit="return validate(this);" method="post"> <tr> <td width="35%">Loginname</td> <td><input type="text" name="loginname" size="25"></td> </tr> <tr> <td align="center" colspan="2"><input type="submit" name="action" value="Submit"></td> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805228 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 it always came out "cannot insert". Is there any error testing script for php? Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805229 Share on other sites More sharing options...
dadamssg Posted April 9, 2009 Share Posted April 9, 2009 and i dont see where you're connecting to your db try this $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die("Couldn't connect"); $sql = "INSERT INTO users (llid, loginname) VALUES ('3','{$loginname}')"; $result = mysqli_query($cxn,$sql) or die (mysqli_error($result)); Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805231 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 database is connected, but it just cannot insert into sql?? Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805233 Share on other sites More sharing options...
dadamssg Posted April 9, 2009 Share Posted April 9, 2009 replace or die ("cannot insert"); with or die (mysqli_error($result)); but you have to set your mysqli_query to a variable like so $result = mysqli_query($cxn,$sql) or die (mysqli_error($result)); Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805234 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 $result=mysql_query("insert into users (loginname) values ('$loginname')") or die (mysql_error($result)); error is "Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in signup.php on line 21" What is it means? Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805239 Share on other sites More sharing options...
dadamssg Posted April 9, 2009 Share Posted April 9, 2009 change mysql to mysqli...see what happens as in $result=mysqli_query("insert into users (loginname) values ('$loginname')") or die (mysqli_error($result)); Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805243 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /home2/sgfairde/public_html/housing/agentsignup.php on line 21 Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805245 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 <?php if($_POST[action]=="Submit") { include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/config.php"); $loginname=$_POST[loginname]; echo "$loginname"; $result=mysql_query("insert into users (loginname) values ('$loginname')") or die (mysqli_error($result)); }else{ ?> <html> <head> <title>Agents Register</title> </head> <body> <table width="400" align="center"> <br> <form name="form" action="<?php echo"$PHP_SELF"; ?>" method="post"> <tr> <td width="35%">Loginname</td> <td><input type="text" name="loginname" size="25"></td> </tr> <tr> <td align="center" colspan="2"><input type="submit" name="action" value="Submit"></td> </tr> </table> </form> </body> </html> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805247 Share on other sites More sharing options...
dadamssg Posted April 9, 2009 Share Posted April 9, 2009 your last else stmt is doing nothing, just delete it, less code Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805251 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 ok it still giving me "Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /home2/sgfairde/public_html/housing/agentsignup.php on line 21" Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805253 Share on other sites More sharing options...
Zane Posted April 9, 2009 Share Posted April 9, 2009 "Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in signup.php on line 21" What is it means? It means that you are trying to connect to your database WITHOUT a proper connection variable...... $result = mysqli_query($cxn,$sql) quickest solution: Switch the parameters! also...you don't need mysqli and you can't call mysql_error() on mysqli connections...if I'm not mistaken....seems pretty logical too using mysqli you'd have to connect like this $cxn = new mysqli("localhost", "my_user", "my_password", "world"); Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805256 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 <? $hostname = "localhost"; $username = "sgfai_winning"; $password = "heally"; $dbName = "sgfai_property"; MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); mysql_select_db("$dbName") or die("Unable to select database"); ?> Hi zanus, is the above connection wrong? Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805262 Share on other sites More sharing options...
dadamssg Posted April 9, 2009 Share Posted April 9, 2009 do this $host="localhost"; $user="sgfai_winning"; $passwd = "heally"; $dbname = "sgfai_property"; $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die("Couldn't connect"); thatll connect you to the right db with the right username, password and you use $cxn in all your mysqli_queries as the first parameter.. like $result = mysqli_query($cxn,$sql) or die (mysqli_error($result)); $sql will be your mysql query Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805265 Share on other sites More sharing options...
Zane Posted April 9, 2009 Share Posted April 9, 2009 I'm sure you've changed your code so much now that I don't even know if you've got mysql with a mysqli connection post all your code again..what you have so far Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805268 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 oh.. all my pages cannot work already... just now only the insert pages, now all other pages cannot work Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805269 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 <?php if($_POST[action]=="Submit") { $hostname = "localhost"; $username = "sgfai_winning"; $password = "helly"; $dbName = "sgfai_property"; MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); mysql_select_db("$dbName") or die("Unable to select database"); $loginname=$_POST[loginname]; echo "$loginname"; $result=mysql_query("insert into users (loginname) values ('$loginname')") or die (mysqli_error($result)); } ?> <html> <head> <title>Agents Register</title> </head> <body> <table width="400" align="center"> <br> <form name="form" action="<?php echo"$PHP_SELF"; ?>" method="post"> <tr> <td width="35%">Loginname</td> <td><input type="text" name="loginname" size="25"></td> </tr> <tr> <td align="center" colspan="2"><input type="submit" name="action" value="Submit"></td> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805278 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 it keep giving me "Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /home2/sgfairde/public_html/housing/agentsignup.php on line 21" but I don't see there is anything wrong? Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805280 Share on other sites More sharing options...
Zane Posted April 9, 2009 Share Posted April 9, 2009 it keep giving me "Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /home2/sgfairde/public_html/housing/agentsignup.php on line 21" but I don't see there is anything wrong? take the i off. Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805281 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /home2/sgfairde/public_html/housing/agentsignup.php on line 22 Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805285 Share on other sites More sharing options...
Zane Posted April 9, 2009 Share Posted April 9, 2009 mysql_error($result) take $result out too Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805287 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 die (mysql_error()); Result : Duplicate entry '' for key 1 Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805288 Share on other sites More sharing options...
sungpeng Posted April 9, 2009 Author Share Posted April 9, 2009 It cannot insert into mysql. Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805289 Share on other sites More sharing options...
Zane Posted April 9, 2009 Share Posted April 9, 2009 Now we're gettin somewhere.... you've got a table structure problem apparently you're primary key in your table isn't incrementing...and it isnt even number based....which I don't think is possible, but it may be...never tried. go find your primary key...set it to autoincrement....and check the datatype to make sure that it is INT or TINYINT of something along the lines of INT Quote Link to comment https://forums.phpfreaks.com/topic/153275-solved-simple-script-cannot-work/#findComment-805291 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.