0

Okay, my head is swimming as I've been trying to figure out what I'm doing wrong here. I am certain it's something stupid and I've tried different ways of putting it all in, but still no luck.

Basically, I am trying to make it so I can put in our crews for the shifts at work, which will be displayed on another page. (I have the display page working fine with some sample data.)

I will also go ahead and ask now...I am wanting to overwrite what I already have in there, so there is only one row in the database. Is this possible or am I going to have to delete rows every day? (Which may end up being a big pain since I only work a 3 day rotation.)

Anyhow...here is the main page. It's a little messy, but it works fine.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">



<head>
<title>HCH EMS</title>

<link href="style.css" rel="stylesheet" type="text/css" />


<!--[if IE]>
<style>
#head_container ul
{
    margin-top: 56px;
}
#content_container
{
    float: left;
}
</style>
<![endif]-->

</head>



<body>


<div id="top">

<div id="head_container">


<ul>

<li><a href="http://hchems.zymichost.com/index.php">Main</a></li>

<li><a href="#">Link</a></li>


</ul>


<a href="index.php" id="logo">HCH EMS Crews</a>



</div>

</div>




<div id="wrapper">

<div id="main_container">


<div id="menu_container">

<div class="content">



<h1> Crews </h1>


<p>

<a href="#">News</a>

<span>5/17/2012</span> 
<br />

Example data

</p>



</div>



<div class="content">


<h1> Links </h1>


<ul>

<li><a href="#">Link Example</a></li>

</ul>


</div>




<div class="content">

<h1> Links2 </h1>

<ul>

<li><a href="#">Link Example</a></li>

</ul>


</div>


</div>




<div id="content_container">



<div class="content">

<h1> 24 Hour Crew </h1>



<form method="post" action="update.php">
Driver: <br />
<input type="text" name="Driver24" size="60" /><br />

Caregiver: <br />
<input type="text" name="Medic24" size="60" /><br />

</div>


</div>



<div id="content_container">



<div class="content">

<h1> Day Crew </h1>


Driver: <br />
<input type="text" name="DriverDay" size="60" /><br />

Caregiver: <br />
<input type="text" name="MedicDay" size="60" /><br />     

</div>


</div>


<div id="content_container">



<div class="content">

<h1> Call Crew </h1>


Driver: <br />
<input type="text" name="DriverCall" size="60" /><br />

Caregiver: <br />
<input type="text" name="MedicCall" size="60" /><br />
<input type="submit" value="Update Crews" />
</form>       

</div>


</div>

<div id="clear">
</div>



</div>

</div>


<div id="footer">

<!-- 

################# DO NOT REMOVE THE ZYMIC LINK! ################
If you remove this link to zymic.com, you risk legal action being
taken against you for infringing on our copyright on this design.
If you would like to remove the link legally, please visit 
http://www.zymic.com/free-templates/copyright-removal/1135/
-->

Copyright &copy; 2007 <a href="http://www.zymic.com/free-templates/">Free Templates</a> by <a href="http://www.zymic.com">Zymic</a> - <a href="http://www.zymic.com/free-web-hosting/">Free Web Hosting</a> - Best Viewed in <a href="http://www.mozillafirefox.us">Mozilla Firefox</a><br />
<a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> | <a href="http://validator.w3.org/check/referer">XHTML</a>
</div>


</body>
</html>

And here is the simply little update file. Now...when I hit submit, it leaves the page, but then simply goes to a white page. I have tried an echo at the end and it does work, so it runs through, but will not write to the database and then just leaves me on a white page. I would like it to return to the display page if at all possible. If not, at least back to the same page I put the information in on. Any thoughts?

<?php

mysql_connect ("localhost", "731517_hchems", "9426333");
mysql_select_db ("hchems_zymichost_hch");

$query="INSERT INTO Crews (ID, Driver24, Medic24, DriverDay, MedicDay, DriverCall, MedicCall) VALUES('$_POST[Driver24]', '$_POST[Medic24]', '$_POST[DriverDay]', '$_POST[MedicDay]', '$_POST[DriverCall]', '$_POST[MedicCall]')";

mysql_query($query);

?>
4
Contributors
8
Replies
10
Views
5 Years
Discussion Span
Last Post by wju2004
0

To do a redirect after the SQL query you would use:
header("location:[page to redirect to]");

To edit existing data in the DB you would want to obtain the data from the DB and display in the text fields:

eg <input type="text" name="Medic24" value="<?php $variable_of_the_data; ?>size="60" />

You would change the "INSERT" into an "UPDATE" statement and use the 'ID' against the WHERE clause

Hope that helps

*EDIT:

You should also clean the form input before inserting/updating the database. don't trust anyone (in regards to form input)

Edited by Squidge

0
mysql_query($query);

change to

mysql_query($query) or die(mysql_error());

or

if(mysql_query($query)){
    //query success do something
    header('Location: http://www.google.co.uk');
}else{
    //query fail do something
}   
0

I do have the redirect working now. Still unable to write to the database as of yet...and trying to work it in so I can update the single row in the database rather than adding any, though suppose I should get the writing to the database down first.

Also, I will be password protecting the entry page as I will only want people working here to change that information.

0

"INSERT INTO Crews (ID, Driver24, Medic24, DriverDay, MedicDay, DriverCall, MedicCall) VALUES('$_POST[Driver24]', '$_POST[Medic24]', '$_POST[DriverDay]', '$_POST[MedicDay]', '$_POST[DriverCall]', '$_POST[MedicCall]')";

UPDATE table_name SET field1=new-value1, field2=new-value2 [WHERE Clause]

update crews set Driver24='$_POST[Driver24]', Medic24='$_POST[Medic24]',DriverDay='$_POST[DriverDay]',MedicDay='$_POST[MedicDay]',DriverCall='$_POST[DriverCall]',MedicCall='$_POST[MedicCall]' WHERE id='$_POST[id]'

0

$query="INSERT INTO Crews (ID, Driver24, Medic24, DriverDay, MedicDay, DriverCall, MedicCall) VALUES('$_POST[Driver24]', '$_POST[Medic24]', '$_POST[DriverDay]', '$_POST[MedicDay]', '$_POST[DriverCall]', '$_POST[MedicCall]')";

Your insert column count doesn't match, take out the ID as that should be auto generated anyway

$query="INSERT INTO Crews (Driver24, Medic24, DriverDay, MedicDay, DriverCall, MedicCall) VALUES('$_POST[Driver24]', '$_POST[Medic24]', '$_POST[DriverDay]', '$_POST[MedicDay]', '$_POST[DriverCall]', '$_POST[MedicCall]')";

you should also do something to escape the $_POST variables such as:

foreach($_POST as $k=>$v){
    $v = str_replace('"','&#34;',$v);
    $v = str_replace("'",'&#39;',$v);
    $v = str_replace('\\','/',$v);
    $_POST[$k] = $v;
}   

to prevent mysql injection

0

Thank you for all the help, guys. It is now writing to the database, though now I just need to change it back to update so it doesn't create a new line in the database each time.

Still do not have it showing what is in there on my "input" page where the crews will put who is in what squad so far, but as long as they can just update that single line, I am happy. Not really dealing with the computer savy, so the easier I can make this, the less headaches it will give me. I had thought of doing drop down boxes, but after thinking about it, sometimes the shifts are split up and would just cause more problems, hence why I left it for them to write it as they need. I'll just have to remind them to mark down a person's shift if it's a split shift.

If I have further problems, I will reply again, but for now...things are looking up.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.