adamdyer Posted August 22, 2007 Share Posted August 22, 2007 Ok, honestly I have NO basic knowledge of PHP MySQL - Im good at dreamweaver and designing but im no good with this - I have to build a database for a Hotel that allows people to register and book rooms etc, however I can type it all in, Its just the connection from 'getting' the information from the Database to the HTML side - I'll paste what I've got so far and hopefully someone can help me :-) (Please?) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <title>View BOOKINGS using PHP</title> <P><B>BOOKING DATABASE</B></P> <hr> <?php # connect to MySQL $conn = @mysql_connect("localhost","ajdref","ref2") or die ("sorry - could not wont connect to MySQL"); # select the specified database $rs = @mysql_select_db("ajdref", $conn) or die ("sorry - could not connect to the ajdref"); #create the query - sets $sql to contain the required query $sql = "SELECT * FROM `Booking Database`"; #execute the query - uses the mysql_query() function to issue the $sql query to the $conn connection #$rs contains the result set in the form of an array $rs = mysql_query($sql,$conn); while ($row=mysql_fetch_array($rs)) { echo($row["Unique ID"]); echo(".."); echo($row["Booking ID"]); echo(".."); echo($row["Customer Name"]); echo(".."); echo($row["Check In"]); echo(".."); echo($row["Check Out"]); echo(".."); echo($row["Price Cat"]); echo(".."); echo($row[""]); echo(".."); echo($row[""]); echo(".."); echo($row[""]); echo(" <hr> "); } ?> <p><A href="index.html" target="_self">EXIT REPORT</A></p> </body> </html> </body> </html> Thanks Guys. EDITED BY akitchin: code tags are good for the mind, body and soul. and for making your post easier to read. please use them. Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/ Share on other sites More sharing options...
piznac Posted August 22, 2007 Share Posted August 22, 2007 First are you getting any errors? Anytime you deal with sql you should show erros to see what the problem may be eg: # connect to MySQL $conn = @mysql_connect("localhost","ajdref","ref2") or die ("sorry - could not wont connect to MySQL" . mysql_error()); What is it doing? Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331095 Share on other sites More sharing options...
MadTechie Posted August 22, 2007 Share Posted August 22, 2007 OK 1st of all, welcome, 2nd please use the code tags (#) when pasting code. 3rd do that code put the database enties onto the page or not ? Basically i am not sure of the question your asking as for the lack of errors remove the @'s (they omit the error) Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331098 Share on other sites More sharing options...
akitchin Posted August 22, 2007 Share Posted August 22, 2007 don't forget to add an or die() clause to your query execution as well, to catch any syntax errors: $rs = mysql_query($sql,$conn) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331100 Share on other sites More sharing options...
adamdyer Posted August 22, 2007 Author Share Posted August 22, 2007 no theres no errors - ive done a print screen to show what happens. The data that the customer enters just isnt recognised. Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331104 Share on other sites More sharing options...
akitchin Posted August 22, 2007 Share Posted August 22, 2007 the screenshot you posted isn't the file script you posted. you posted the VIEW BOOKINGS page, while that screenshot is of the Add customer page.. Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331106 Share on other sites More sharing options...
MadTechie Posted August 22, 2007 Share Posted August 22, 2007 akitchin:is on top form to(night|day)(i noticed as well) speedy reply Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331109 Share on other sites More sharing options...
adamdyer Posted August 22, 2007 Author Share Posted August 22, 2007 Yeah , sorry about that guys I copied the wrong code at the start - this is the add customer code - so the Print Screen is now right. :-) <HTML> <HEAD> <TITLE>Add customer to database</TITLE> </HEAD> <BODY> </br> Your Inputs Were : </p> <?php $CID = $_GET['Unique ID']; echo( "Unique ID = <B>$CID</B></br>" ); $CID = $_GET['Booking ID']; echo( "Booking ID = <B>$CID</B></br>" ); $CID = $_GET['Customer Name']; echo( "Customer Name = <B>$CID</B></br>" ); $CID = $_GET['Check In']; echo( "Check In = <B>$CID</B></br>" ); $CID = $_GET['Check Out']; echo( "Check Out = <B>$CID</B></br>" ); $CID = $_GET['Price Cat']; echo( "Price Cat = <B>$CID</B></br>" ); $CID = $_GET['Type Of Room']; echo( "Type Of Room = <B>$CID</B></br>" ); $CID = $_GET['Password']; echo( "Password = <B>$CID</B></br>" ); # connect to MySQL $conn = @mysql_connect("localhost","ajdref","ref2") or die ("sorry - could not wont connect to MySQL"); # select the specified database $rs = @mysql_select_db("ajdref", $conn) or die ("sorry - could not connect to the ajdref"); #create the query - sets $sql to contain the required query $sql = "SELECT * FROM `Booking Database`"; $sql = "INSERT INTO `Booking Database` (Unique ID, Booking ID, Customer Name, Check In, Check Out, Price Cat, Type Of Room, Password) VALUES ( '$CID', 'use the variable names you defined earlier' )"; $rs=mysql_query($sql,$conn); if($rs){ echo("Customer added");} else { echo("Error! Customer not added");} ?> <p><A href="index.html" target="_self">MAIN MENU</A></p> </BODY> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331117 Share on other sites More sharing options...
MadTechie Posted August 22, 2007 Share Posted August 22, 2007 update the $CID to the names $UniqueID= $_GET['Unique ID']; echo( "Unique ID = <B>$UniqueID</B></br>" ); $BookingID= $_GET['Booking ID']; echo( "Booking ID = <B>$BookingID</B></br>" ); etc etc now update the $SQL $sql = "INSERT INTO `Booking Database` (Unique ID, Booking ID, Customer Name, Check In, Check Out, Price Cat, Type Of Room, Password) VALUES ( '$UniqueID', '$BookingID', etc etc etc )"; EDIT: update mysql_query($sql,$conn); to mysql_query($sql,$conn)or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331119 Share on other sites More sharing options...
akitchin Posted August 22, 2007 Share Posted August 22, 2007 it looks like you're passing the GET string incorrectly. your string should look like this: filename.php?Customer Name=something&Check In=something keep in mind those spaces should be %20, not + or anything else. furthermore, you need to use different variable names for each $_GET variable you're using, rather than $CID for each one because it will simply be overridden each time. your SELECT is unnecessary here. EDIT: MadTechie covered the $CID issue, nevermind that. Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331127 Share on other sites More sharing options...
adamdyer Posted August 22, 2007 Author Share Posted August 22, 2007 Ok So ive done what you guys have said but it stil saying its wrong :'( <HTML> <HEAD> <TITLE>Add customer to database</TITLE> </HEAD> <BODY> </br> Your Inputs Were : </p> <?php $UniqueID= $_GET['Unique ID']; echo( "Unique ID = <B>$CID</B></br>" ); $BookingID= $_GET['Booking ID']; echo( "Booking ID = <B>$CID</B></br>" ); $CustomerName= $_GET['Customer Name']; echo( "Customer Name = <B>$CID</B></br>" ); $CheckIn= $_GET['Check In']; echo( "Check In = <B>$CID</B></br>" ); $CheckOut= $_GET['Check Out']; echo( "Check Out = <B>$CID</B></br>" ); $PriceCat= $_GET['Price Cat']; echo( "Price Cat = <B>$CID</B></br>" ); $TypeOfRoom= $_GET['Type Of Room']; echo( "Type Of Room = <B>$CID</B></br>" ); $Password= $_GET['Password']; echo( "Password = <B>$CID</B></br>" ); # connect to MySQL $conn = @mysql_connect("localhost","ajdref","ref2") or die ("sorry - could not wont connect to MySQL"); # select the specified database $rs = @mysql_select_db("ajdref", $conn) or die ("sorry - could not connect to the ajdref"); #create the query - sets $sql to contain the required query $sql = "SELECT * FROM `Booking Database`"; $sql = "INSERT INTO `Booking Database` (Unique ID, Booking ID, Customer Name, Check In, Check Out, Price Cat, Type Of Room, Password) VALUES ( '$UniqueID', '$BookingID', '$CustomerName', '$CheckIn', '$CheckOut', '$PriceCat', '$TypeOfRoom', '$Password' )"; mysql_query($sql,$conn)or die(mysql_error()); if($rs){ echo("Customer added");} else { echo("Error! Customer not added");} ?> <p><A href="index.html" target="_self">MAIN MENU</A></p> </BODY> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331136 Share on other sites More sharing options...
MadTechie Posted August 22, 2007 Share Posted August 22, 2007 it looks like you're passing the GET string incorrectly. your string should look like this: filename.php?Customer Name=something&Check In=something OR the form method="get" not form method="post" if you are using method="post" then you can replace the $_GET with $_POST Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331138 Share on other sites More sharing options...
MadTechie Posted August 22, 2007 Share Posted August 22, 2007 change $sql = "INSERT INTO `Booking Database` (Unique ID, Booking ID, Customer Name, Check In, Check Out, Price Cat, Type Of Room, Password) VALUES ( '$UniqueID', '$BookingID', '$CustomerName', '$CheckIn', '$CheckOut', '$PriceCat', '$TypeOfRoom', '$Password' )"; to $sql = "INSERT INTO `Booking Database` (`Unique ID`, `Booking ID`, `Customer Name`, `Check In`, `Check Out`, `Price Cat`, `Type Of Room`, `Password`) VALUES ( '$UniqueID', '$BookingID', '$CustomerName', '$CheckIn', '$CheckOut', '$PriceCat', '$TypeOfRoom', '$Password' )"; also your not getting the data, read my last post Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331141 Share on other sites More sharing options...
adamdyer Posted August 22, 2007 Author Share Posted August 22, 2007 ok , so now its actually saying theres a customer added which is good, but your right the data is not being added. sorry for being stupid - but im not sure what Im meant to do with this bit: it looks like you're passing the GET string incorrectly. your string should look like this: Code: filename.php?Customer Name=something&Check In=something Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331149 Share on other sites More sharing options...
piznac Posted August 22, 2007 Share Posted August 22, 2007 Can you post the code for the form where this data is drawn from? Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331154 Share on other sites More sharing options...
akitchin Posted August 22, 2007 Share Posted August 22, 2007 look at your current URL: addcustomer.php?Customer+Username=000009&Booking+ID=000009A ... that '+' means nothing to the GET query. you need to replace those with spaces or with %20, or, for better practice, use underscores rather than whitespace of any kind: addcustomer.php?Customer_Username=000009&Booking_ID=000009A ... Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331158 Share on other sites More sharing options...
adamdyer Posted August 22, 2007 Author Share Posted August 22, 2007 sorry ' akitchin ' - but i am pretty dumb addcustomer.php?Customer+Username=000009&Booking+ID=000009A ... where is that in my code? <HTML> <HEAD> <TITLE>Add customer to database</TITLE> </HEAD> <BODY> </br> Your Inputs Were : </p> <?php $UniqueID= $_GET['Unique ID']; echo( "Unique ID = <B>$CID</B></br>" ); $BookingID= $_GET['Booking ID']; echo( "Booking ID = <B>$CID</B></br>" ); $CustomerName= $_GET['Customer Name']; echo( "Customer Name = <B>$CID</B></br>" ); $CheckIn= $_GET['Check In']; echo( "Check In = <B>$CID</B></br>" ); $CheckOut= $_GET['Check Out']; echo( "Check Out = <B>$CID</B></br>" ); $PriceCat= $_GET['Price Cat']; echo( "Price Cat = <B>$CID</B></br>" ); $TypeOfRoom= $_GET['Type Of Room']; echo( "Type Of Room = <B>$CID</B></br>" ); $Password= $_GET['Password']; echo( "Password = <B>$CID</B></br>" ); # connect to MySQL $conn = @mysql_connect("localhost","ajdref","ref2") or die ("sorry - could not wont connect to MySQL"); # select the specified database $rs = @mysql_select_db("ajdref", $conn) or die ("sorry - could not connect to the ajdref"); #create the query - sets $sql to contain the required query $sql = "SELECT * FROM `Booking Database`"; $sql = "INSERT INTO `Booking Database` (`Unique ID`, `Booking ID`, `Customer Name`, `Check In`, `Check Out`, `Price Cat`, `Type Of Room`, `Password`) VALUES ( '$UniqueID', '$BookingID', '$CustomerName', '$CheckIn', '$CheckOut', '$PriceCat', '$TypeOfRoom', '$Password' )"; mysql_query($sql,$conn)or die(mysql_error()); if($rs){ echo("Customer added");} else { echo("Error! Customer not added");} ?> <p><A href="index.html" target="_self">MAIN MENU</A></p> </BODY> </HTML> heres also the HTML side of it if that makes a difference: <HTML> <HEAD> </HEAD> <BODY BGCOLOR=lemonchiffon> <form NAME="GetCode" ACTION="addcustomer.php" METHOD=get> <FONT size=4>New customer registration form</FONT> <P><b>Fill in the following fields then click 'Send' at the bottom of the page.</b> </P> <p>Customer Username ( max 6 characters ) <INPUT Name ="Customer Username" size = 6 > </p> <P>Booking ID <INPUT Name ="Booking ID" size = 30 > </P> <P>Customer Name <INPUT Name ="Customer Name" size = 60 > </P> <p>Check In <INPUT Name ="Check In" size = 20 > </p> <p>Check Out <INPUT Name ="Check Out" size = 40 > </p> <p>Price Cat <INPUT Name = "Price Cat" size= 20 > </p> <p>Type Of Room <INPUT Name = "Type Of Room" size= 20 > </p> <p> Password <INPUT Name = "Password" type="password" size= 20 > </p> <p> <p> <b>Now click 'Send', or 'Clear' to reset the answer boxes to their initial default values. </b></p> <div align="left"> <input type="reset" value="Clear" name="RESET"> <input type="submit" value="Send" name="SUBMIT" > <p><A href="index.html" target="_self">EXIT WITHOUT REGISTERING</A></p> </div> </form> </BODY> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331167 Share on other sites More sharing options...
MadTechie Posted August 22, 2007 Share Posted August 22, 2007 change <form NAME="GetCode" ACTION="addcustomer.php" METHOD=get> to <form NAME="GetCode" ACTION="addcustomer.php" METHOD="get"> Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331169 Share on other sites More sharing options...
piznac Posted August 22, 2007 Share Posted August 22, 2007 Why wouldnt you just use the post method? Then instead of using $_GET['some_stuff'] use $_POST['some_stuff'],... seems more secure to me that way. Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331173 Share on other sites More sharing options...
thryb Posted August 22, 2007 Share Posted August 22, 2007 <INPUT Name ="Customer_Username" size = 6 > </p> <P>Booking ID <INPUT Name ="Booking_ID" size = 30 > </P> <P>Customer Name <INPUT Name ="Customer_Name" size = 60 > </P> <p>Check In <INPUT Name ="Check_In" size = 20 > </p> <p>Check Out <INPUT Name ="Check_Out" size = 40 > </p> <p>Price Cat <INPUT Name = "Price_Cat" size= 20 > </p> <p>Type Of Room <INPUT Name = "Type_Of_Room" size= 20 > </p> All you space should be replaced by _ the browser dont understand spaces as well you need to do those too sorry $UniqueID= $_GET['Unique_ID']; echo( "Unique ID = <B>$UniqueID</B></br>" ); $BookingID= $_GET['Booking_ID']; echo( "Booking ID = <B>$BookingID</B></br>" ); $CustomerName= $_GET['Customer_Name']; echo( "Customer Name = <B>$CustomerName</B></br>" ); $CheckIn= $_GET['Check_In']; echo( "Check In = <B>$CheckIn</B></br>" ); $CheckOut= $_GET['Check_Out']; echo( "Check Out = <B>$CheckOut</B></br>" ); $PriceCat= $_GET['Price_Cat']; echo( "Price Cat = <B>$PriceCat</B></br>" ); $TypeOfRoom= $_GET['Type_Of_Room']; echo( "Type Of Room = <B>$TypeOfRoom</B></br>" ); Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331175 Share on other sites More sharing options...
MadTechie Posted August 22, 2007 Share Posted August 22, 2007 Not sure how its more secure ? but i do use POST for forms and GET for links.. if you do want this then change <form NAME="GetCode" ACTION="addcustomer.php" METHOD=get> to <form NAME="GetCode" ACTION="addcustomer.php" METHOD="POST"> and the $_GET in the php to $_POST EDIT: personally i would remove the spaces remember to update the php if you do Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331177 Share on other sites More sharing options...
piznac Posted August 22, 2007 Share Posted August 22, 2007 Well call it a fear,.. I dont like to see my data transfered in the URL if I can help it Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331178 Share on other sites More sharing options...
adamdyer Posted August 22, 2007 Author Share Posted August 22, 2007 HEY! it kinda works, now when I add a customer , I check PhpMyAdmin and the data is there, except one small snag - whenever I ask the customer to enter their 'Customer Username' - whatever they type, in my PhpMyAdmin, the username always says - Username...instead of what the customer has typed ??? Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331202 Share on other sites More sharing options...
MadTechie Posted August 22, 2007 Share Posted August 22, 2007 can you post the code $SQL = "INSERT INTO blar blar blar blar blar blar Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331263 Share on other sites More sharing options...
adamdyer Posted August 22, 2007 Author Share Posted August 22, 2007 $sql = "INSERT INTO `Booking Database` (`Customer Username`, `Booking ID`, `Customer Name`, `Check In`, `Check Out`, `Price Cat`, `Type Of Room`, `Password`) VALUES ( '$Customer Username', '$BookingID', '$CustomerName', '$CheckIn', '$CheckOut', '$PriceCat', '$TypeOfRoom', '$Password' )"; Quote Link to comment https://forums.phpfreaks.com/topic/66195-running-queries-hey-guys-please-help-uni-student-doing-his-re-sits/#findComment-331267 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.